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

Class: File_Archive

Source Location: /File_Archive-0.2.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 405]

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 438]

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 580]

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 544]

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 556]

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 519]

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 425]

void predFalse( )

Predicate that always evaluate to false
  • See: File_Archive_Predicate_False

[ Top ]

predMaxDepth   [line 507]

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 532]

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 483]

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 495]

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 472]

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 456]

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 415]

void predTrue( )

Predicate that always evaluate to true
  • See: File_Archive_Predicate_True

[ Top ]

read   [line 159]

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

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
 

readUncompress('.') 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
 

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

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

readUncompress('.', '', -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
 

readUncompress('.', '', 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
 

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

 a.txt
 b.tar
 

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

 a.txt
 b.tar
 dir2/g.txt
 

readUncompress('.', '', -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 readUncompress('.', '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
 

You can use the source parameter to create a reader that reads the given URL from a specific reader instead of reading from 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


[ Top ]

readConcat   [line 391]

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

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

[ Top ]

readMemory   [line 346]

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 361]

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 ]

toArchive   [line 665]

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

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 Tar, Gz, Tgz, Zip (default is the extension of $filename). 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.

[ Top ]

toFiles   [line 610]

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 597]

void toMail( mixed $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

[ Top ]

toMemory   [line 623]

void toMemory( [out &$data = null])

Send the content of the files to a memory buffer
  • 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 634]

void toMulti( mixed &$a, mixed &$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

[ Top ]

toOutput   [line 647]

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 ]


Documentation generated on Thu, 24 Feb 2005 12:50:14 -0500 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.