apidoc
[ class tree: apidoc ] [ index: apidoc ] [ all elements ]

Class: File_Archive

Source Location: /File_Archive-1.0.0/File/Archive.php

Class Overview


Factory to access the most common File_Archive features


Methods


Inherited Variables

Inherited Methods


Class Details

[line 45]
Factory to access the most common File_Archive features

It uses lazy include, so you dont have to include the files from File/Archive/* directories



[ Top ]


Method Detail

filter   [line 415]

void filter( File_Archive_Predicate $predicate, File_Archive_Reader $source)

Removes from a source the files that do not follow a given predicat
  • See: File_Archive_Reader_Filter

Parameters:

File_Archive_Predicate   $predicate   —  Only the files for which $predicate->isTrue() will be kept
File_Archive_Reader   $source   —  Source that will be filtered

[ Top ]

predAnd   [line 448]

void predAnd( File_Archive_Predicate 0)

Predicate that evaluates to the logical AND of the parameters You can add other predicates thanks to the File_Archive_Predicate_And::addPredicate() function
  • See: File_Archive_Predicate_And

Parameters:

File_Archive_Predicate   0   —  (any number of them)

[ Top ]

predCustom   [line 590]

void predCustom( string $expression)

Custom predicate built by supplying a string expression

Example: new File_Archive_Predicate_Custom("return strlen($name)<100;") new File_Archive_Predicate_Custom("strlen($name)<100;") new File_Archive_Predicate_Custom("strlen($name)<100") new File_Archive_Predicate_Custom("strlen($source->getFilename())<100")

  • See: File_Archive_Predicate_Custom

Parameters:

string   $expression   —  String containing an expression that evaluates to a boolean. If the expression doesn't contain a return statement, it will be added at the begining of the expression A ';' will be added at the end of the expression so that you don't have to write it. You may use the $name variable to refer to the current filename (with path...), $time for the modification time (unix timestamp), $size for the size of the file in bytes, $mime for the MIME type of the file

[ Top ]

predEreg   [line 554]

void predEreg( string $ereg)

Evaluates to true iif the name of the file follow a given regular expression
  • See: File_Archive_Predicate_Ereg, ereg()

Parameters:

string   $ereg   —  regular expression that the filename must follow

[ Top ]

predEregi   [line 566]

void predEregi( string $ereg)

Evaluates to true iif the name of the file follow a given regular expression (case insensitive version)
  • See: File_Archive_Predicate_Eregi, eregi

Parameters:

string   $ereg   —  regular expression that the filename must follow

[ Top ]

predExtension   [line 529]

void predExtension( array $list)

Evaluates to true iif the extension of the file is in a given list
  • See: File_Archive_Predicate_Extension

Parameters:

array   $list   —  or string $list List or comma separated string of possible extension of the files

[ Top ]

predFalse   [line 435]

void predFalse( )

Predicate that always evaluate to false
  • See: File_Archive_Predicate_False

[ Top ]

predMaxDepth   [line 517]

void predMaxDepth( int $depth)

Evaluates to true iif the file has less that a given number of directories in its path
  • See: File_Archive_Predicate_MaxDepth

Parameters:

int   $depth   —  Maximal number of directories in path of the files

[ Top ]

predMIME   [line 542]

void predMIME( array $list)

Evaluates to true iif the MIME type of the file is in a given list
  • See: File_Archive_Predicate_MIME, MIME_Type::isWildcard()

Parameters:

array   $list   —  or string $list List or comma separated string of possible MIME types of the files. You may enter wildcards like "image/*" to select all the MIME in class image

[ Top ]

predMinSize   [line 493]

void predMinSize( int $size)

Evaluates to true iif the file is larger than a given size
  • See: File_Archive_Predicate_MinSize

Parameters:

int   $size   —  the minimal size of the files (in Bytes)

[ Top ]

predMinTime   [line 505]

void predMinTime( int $time)

Evaluates to true iif the file has been modified after a given time
  • See: File_Archive_Predicate_MinTime

Parameters:

int   $time   —  Unix timestamp of the minimal modification time of the files

[ Top ]

predNot   [line 482]

void predNot( File_Archive_Predicate $pred)

Negate a predicate
  • See: File_Archive_Predicate_Not

Parameters:

File_Archive_Predicate   $pred   —  Predicate to negate

[ Top ]

predOr   [line 466]

void predOr( File_Archive_Predicate 0)

Predicate that evaluates to the logical OR of the parameters You can add other predicates thanks to the File_Archive_Predicate_Or::addPredicate() function
  • See: File_Archive_Predicate_Or

Parameters:

File_Archive_Predicate   0   —  (any number of them)

[ Top ]

predTrue   [line 425]

void predTrue( )

Predicate that always evaluate to true
  • See: File_Archive_Predicate_True

[ Top ]

read   [line 338]

void read( $URL, [ $symbolic = null], [ $uncompression = 0], [ $directoryDepth = -1])


Parameters:

   $URL   — 
   $symbolic   — 
   $uncompression   — 
   $directoryDepth   — 

[ Top ]

readConcat   [line 401]

void readConcat( &$source, string $filename, [array $stat = array()], [string $mime = null], File_Archive_Reader $source)

Make the files of a source appear as one large file whose content is the concatenation of the content of all the files
  • See: File_Archive_Reader_Concat

Parameters:

File_Archive_Reader   $source   —  The source whose files must be concatened
string   $filename   —  name of the only file of the created reader
array   $stat   —  statistics of the file. Index 7 (size) will be overwritten to match the total size of the files
string   $mime   —  mime type of the file. Default will determine the mime type thanks to the extension of $filename
   &$source   — 

[ Top ]

readMemory   [line 356]

void readMemory( string $memory, string $filename, [array $stat = array()], [string $mime = null])

Contains only one file with data read from a memory buffer
  • See: File_Archive_Reader_Memory

Parameters:

string   $memory   —  content of the file
string   $filename   —  public name of the file
array   $stat   —  statistics of the file. Index 7 (size) will be overwritten to match the size of $memory
string   $mime   —  mime type of the file. Default will determine the mime type thanks to the extension of $filename

[ Top ]

readMulti   [line 371]

void readMulti( [array $sources = array()])

Contains several other sources. Take care the sources don't have several files with the same filename. The sources are given as a parameter, or can be added thanks to the reader addSource method
  • See: File_Archive_Reader_Multi, File_Archive::read()

Parameters:

array   $sources   —  Array of strings or readers that will be added to the multi reader. If the parameter is a string, a reader will be built thanks to the read function

[ Top ]

readSource   [line 159]

void readSource( &$source, $URL, [ $symbolic = null], [ $uncompression = 0], [ $directoryDepth = -1])

Create a reader to read the URL $URL.

If the URL is a directory, it will recursively read that directory. If $uncompressionLevel is not null, the archives (files with extension tar, zip, gz or tgz) will be considered as directories (up to a depth of $uncompressionLevel if $uncompressionLevel > 0). The reader will only read files with a directory depth of $directoryDepth. It reader will replace the given URL ($URL) with $symbolic in the public filenames The default symbolic name is the last filename in the URL (or '' for directories)

Examples: Considere the following file system

 a.txt
 b.tar (archive that contains the following files)
     c.txt
     d.tgz (archive that contains the following files)
         e.txt
         dir1/
             f.txt
 dir2/
     g.txt
     dir3/
         h.tar (archive that contains the following files)
             i.txt

read('.') will return a reader that gives access to following files (recursively read current dir):

 a.txt
 b.tar
 dir2/g.txt
 dir2/dir3/h.tar

read('.', 'myBaseDir') will return the following reader:

 myBaseDir/a.txt
 myBaseDir/b.tar
 myBaseDir/dir2/g.txt
 myBaseDir/dir2/dir3/h.tar

read('.', '', -1) will return the following reader (uncompress everything)

 a.txt
 b.tar/c.txt
 b.tar/d.tgz/e.txt
 b.tar/d.tgz/dir1/f.txt
 dir2/g.txt
 dir2/dir3/h.tar/i.txt

read('.', '', 1) will uncompress only one level (so d.tgz will not be uncompressed):

 a.txt
 b.tar/c.txt
 b.tar/d.tgz
 dir2/g.txt
 dir2/dir3/h.tar/i.txt

read('.', '', 0, 0) will not recurse into subdirectories

 a.txt
 b.tar

read('.', '', 0, 1) will recurse only one level in subdirectories

 a.txt
 b.tar
 dir2/g.txt

read('.', '', -1, 2) will uncompress everything and recurse in only 2 levels in subdirectories or archives

 a.txt
 b.tar/c.txt
 b.tar/d.tgz/e.txt
 dir2/g.txt

The recursion level is determined by the real path, not the symbolic one. So read('.', 'myBaseDir', -1, 2) will result to the same files:

 myBaseDir/a.txt
 myBaseDir/b.tar/c.txt
 myBaseDir/b.tar/d.tgz/e.txt (accepted because the real depth is 2)
 myBaseDir/dir2/g.txt

Use readSource to do the same thing, reading from a specified reader instead of reading from the system files

To read a single file, you can do read('a.txt', 'public_name.txt') If no public name is provided, the default one is the name of the file read('dir2/g.txt') contains the single file named 'g.txt' read('b.tar/c.txt') contains the single file named 'c.txt'

Note: This function uncompress files reading their extension The compressed files must have a tar, zip, gz or tgz extension Since it is impossible for some URLs to use is_dir or is_file, this function may not work with URLs containing folders which name ends with such an extension


Parameters:

   &$source   — 
   $URL   — 
   $symbolic   — 
   $uncompression   — 
   $directoryDepth   — 

[ Top ]

registerStream   [line 765]

string registerStream( File_Archive_Reader &$object)

Register a stream that allows an interface between File_Archive and PHP streams

After having called this function, the streams of the form filearchive://reader/path/to/file and filearchive://writer/path/to/file will be available (the first one in "r" mode, the second one in "w" mode). reader and writer are values returned by the registerStream function

  • Return: Value to put in the URL to refere to the registered reader / writer The complete URL is of the form file_archive://value/path/to/file where value is the value returned by this function

Parameters:

File_Archive_Reader   &$object   —  or File_Archive_Writer $object Reader or writer to register

[ Top ]

toArchive   [line 687]

void toArchive( string $filename, &$innerWriter, [string $type = null], [array $stat = array()], [bool $autoClose = true], File_Archive_Writer $innerWriter)

Compress the data to a tar, gz, tar/gz or zip format

Parameters:

string   $filename   —  name of the archive file
File_Archive_Writer   $innerWriter   —  writer where the archive will be written
string   $type   —  can be one of tgz, tbz, tar, zip, gz, gzip, bz2, bzip2 (default is the extension of $filename) or any composition of them (for example tar.gz or tar.bz2). The case of this parameter is not important.
array   $stat   —  Statistics of the archive (see stat function)
bool   $autoClose   —  If set to true, $innerWriter will be closed when the returned archive is close. Default value is true.
   &$innerWriter   — 

[ Top ]

toFiles   [line 620]

void toFiles( [string $baseDir = ""])

Write the files on the hard drive
  • See: File_Archive_Writer_Files

Parameters:

string   $baseDir   —  if specified, the files will be created in that directory. If they don't exist, the directories will automatically be created

[ Top ]

toMail   [line 607]

void toMail( $to, array $headers, string $message, [Mail $mail = null])

Send the files as a mail attachment
  • See: File_Archive_Writer_Mail

Parameters:

Mail   $mail   —  Object used to send mail (see Mail::factory)
array   $headers   —  or String $to An array or a string with comma separated recipients
string   $message   —  Text body of the mail
   $to   — 

[ Top ]

toMemory   [line 639]

void toMemory( out $data)

Send the content of the files to a memory buffer

toMemory returns a writer where the data will be written. In this case, the data is accessible using the getData member

toVariable returns a writer that will write into the given variable

  • See: File_Archive_Writer_Memory

Parameters:

out   $data   —  if specified, the data will be written to this buffer Else, you can retrieve the buffer with the File_Archive_Writer_Memory::getData() function

[ Top ]

toMulti   [line 655]

void toMulti( &$a, &$b, File_Archive_Writer $a,)

Duplicate the writing operation on two writers
  • See: File_Archive_Writer_Multi

Parameters:

File_Archive_Writer   $a,   —  $b writers where data will be duplicated
   &$a   — 
   &$b   — 

[ Top ]

toOutput   [line 668]

void toOutput( [bool $sendHeaders = true])

Send the content of the files to the standard output (so to the client for a website)
  • See: File_Archive_Writer_Output

Parameters:

bool   $sendHeaders   —  If true some headers will be sent to force the download of the file. Default value is true

[ Top ]

toVariable   [line 644]

void toVariable( &$v)


Parameters:

   &$v   — 

[ Top ]

unregisterStream   [line 779]

void unregisterStream( $name, [ $autoClose = true])

Unregister the name returned by registerStream to free memory and resources

After this call, the streams of type filearchive://$name/ will no longer be valid


Parameters:

   $name   — 
   $autoClose   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:21:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.