eZPublishCommunityProject(LegacyStack)  2013.9
eZFileHandler Class Referenceabstract

Interface for file handlers. More...

+ Inheritance diagram for eZFileHandler:

Public Member Functions

 close ()
 
 doClose ()
 
 doEOF ()
 
 doFlush ()
 
 doOpen ($filename, $mode)
 
 doPasstrough ($closeFile=true)
 
 doRead ($length=false)
 
 doRewind ()
 
 doSeek ($offset, $whence)
 
 doTell ()
 
 doWrite ($data, $length=false)
 
 duplicate ()
 
 eof ()
 
 error ()
 
 errorNumber ()
 
 errorString ()
 
 exists ($filename=false)
 
 eZFileHandler ($handlerIdentifier=false, $handlerName=false)
 
 filename ()
 
 flush ()
 
 identifier ()
 
 isBinaryMode ()
 
 isDirectory ($filename=false)
 
 isExecutable ($filename=false)
 
 isFile ($filename=false)
 
 isLink ($filename=false)
 
 isOpen ()
 
 isReadable ($filename=false)
 
 isWriteable ($filename=false)
 
 mode ()
 
 name ()
 
 open ($filename, $mode, $binaryFile=true)
 
 passtrough ($closeFile=true)
 
 read ($length=false)
 
 rename ($destinationFilename, $sourceFilename=false)
 
 rewind ()
 
 seek ($offset, $whence=SEEK_SET)
 
 statistics ($filename=false)
 
 tell ()
 
 unlink ($filename=false)
 
 write ($data, $length=false)
 

Static Public Member Functions

static copy ($sourceFilename, $destinationFilename)
 
static doExists ($filename)
 
static doIsDirectory ($filename)
 
static doIsExecutable ($filename)
 
static doIsFile ($filename)
 
static doIsLink ($filename)
 
static doIsReadable ($filename)
 
static doIsWriteable ($filename)
 
static doRename ($destinationFilename, $sourceFilename)
 
static doStatistics ($filename)
 
static doUnlink ($filename)
 
static instance ($identifier, $filename=false, $mode=false, $binaryFile=true)
 Returns a shared instance of the eZFileHandler class. More...
 
static isAvailable ()
 
static link ($sourceFilename, $destinationFilename)
 
static linkCopy ($sourceFilename, $destinationFilename, $symbolicLink=true)
 
static move ($sourceFilename, $destinationFilename)
 
static symlink ($sourceFilename, $destinationFilename)
 

Public Attributes

 $FileName
 
 $IsBinary
 
 $IsOpen
 
 $Mode
 
 $Name
 

Detailed Description

Interface for file handlers.

Generic interface for all file handlers.

Using this class i divided into five areas, they are:

File handling using open(), close(), read(), write() and flush().

File position handling using seek(), tell(), rewind() and eof().

Quick output of the file using passtrough().

Error handling with error(), errorString() and errorNumber().

Creating specific handlers

The file handlers must inherit from this class and reimplement some virtual functions.

For dealing with files the following functions must be reimplemented. doOpen(), doClose(), doRead(), doWrite() and doFlush().

For dealing with file positions the following functions must be reimplemented. doSeek(), doTell(), doRewind() and doEOF().

For dealing with quick output the passtrough() function must be reimplemented, if not reimplemented the default implemententation will simply read n bytes using read() and output it with print.

Also the errorString() and errorNumber() functions must be reimplemented to provide proper error handler. The error() function is not required to be implemented since it has a default implementation, for speed it might be wise to implement the function.

This class will handle most of the generic logic, like checking that the filename is correct and if the open succeded, and give error messages based on this. The actual implementations will only have to execute the specific code and return a result.

Member Function Documentation

eZFileHandler::close ( )

Tries to close an open file and returns true if succesful, false otherwise.

Referenced by rename(), and unlink().

eZFileHandler::doClose ( )
pure virtual

Does the actual file closing.

See Also
close

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by close().

eZFileHandler::doEOF ( )
pure virtual

Does the actual file eof detection.

See Also
eof

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, and eZForwardCompressionHandler.

Referenced by eof().

static eZFileHandler::doExists (   $filename)
staticpure virtual

Does the actual file exists checking.

See Also
exists

Referenced by exists().

eZFileHandler::doFlush ( )
pure virtual

Does the actual file flushing.

See Also
flush

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by flush().

static eZFileHandler::doIsDirectory (   $filename)
staticpure virtual

Does the actual directory checking.

See Also
isDirectory

Referenced by isDirectory().

static eZFileHandler::doIsExecutable (   $filename)
staticpure virtual

Does the actual executable checking.

See Also
isExecutable

Referenced by isExecutable().

static eZFileHandler::doIsFile (   $filename)
staticpure virtual

Does the actual file checking.

See Also
isFile

Referenced by isFile().

static eZFileHandler::doIsLink (   $filename)
staticpure virtual

Does the actual link checking.

See Also
isLink

Referenced by isLink().

static eZFileHandler::doIsReadable (   $filename)
staticpure virtual

Does the actual readable checking.

See Also
isReadable

Referenced by isReadable().

static eZFileHandler::doIsWriteable (   $filename)
staticpure virtual

Does the actual writeable checking.

See Also
isWriteable

Referenced by isWriteable().

eZFileHandler::doOpen (   $filename,
  $mode 
)
pure virtual

Does the actual file opening.

See Also
open

Implemented in eZGZIPShellCompressionHandler, eZGZIPZLIBCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by open().

eZFileHandler::doPasstrough (   $closeFile = true)
pure virtual

Does the actual file passtrough.

See Also
eof

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, and eZForwardCompressionHandler.

Referenced by passtrough().

eZFileHandler::doRead (   $length = false)
pure virtual

Does the actual file reading.

See Also
read

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by read().

static eZFileHandler::doRename (   $destinationFilename,
  $sourceFilename 
)
staticpure virtual

Does the actual file renaming.

See Also
rename

Referenced by rename().

eZFileHandler::doRewind ( )

Does the actual file rewind.

See Also
rewind
Note
Default implementation calls seek with offset set to 0 from the file start.

Referenced by rewind().

eZFileHandler::doSeek (   $offset,
  $whence 
)
pure virtual

Does the actual file seek.

See Also
seek

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, and eZForwardCompressionHandler.

Referenced by doRewind(), and seek().

static eZFileHandler::doStatistics (   $filename)
staticpure virtual

Does the actual writeable checking.

See Also
isWriteable

Referenced by statistics().

eZFileHandler::doTell ( )
pure virtual

Does the actual file telling.

See Also
tell

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, and eZForwardCompressionHandler.

Referenced by tell().

static eZFileHandler::doUnlink (   $filename)
staticpure virtual

Does the actual file unlinking.

See Also
unlink

Referenced by unlink().

eZFileHandler::doWrite (   $data,
  $length = false 
)
pure virtual

Does the actual file writing.

See Also
write

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by write().

eZFileHandler::duplicate ( )

Creates a copy of the current handler and returns a reference to the copy.

Note
The default does a simple copy of $this, this method must be reimplemented for specific handlers.
eZFileHandler::eof ( )
Returns
true if the file pointer is at the end of the file or an error occured, otherwise false.
eZFileHandler::error ( )

Returns error data as an associative array, the array contains:

eZFileHandler::errorNumber ( )
pure virtual
Returns
the error number from the last error that occured.

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by error().

eZFileHandler::errorString ( )
pure virtual
Returns
the error string from the last error that occured.

Implemented in eZGZIPZLIBCompressionHandler, eZGZIPShellCompressionHandler, eZForwardCompressionHandler, and eZBZIP2Handler.

Referenced by error().

eZFileHandler::exists (   $filename = false)
Returns
true if the filename $filename exists. If $filename is not specified the filename is taken from the one used in open().
eZFileHandler::eZFileHandler (   $handlerIdentifier = false,
  $handlerName = false 
)

Initializes the handler. Optionally the parameters $filename and $mode may be provided to automatically open the file.

Referenced by eZCompressionHandler\eZCompressionHandler(), and instance().

eZFileHandler::filename ( )
Returns
the filename currently in use.

Referenced by eZGZIPZLIBCompressionHandler\doPasstrough(), and rename().

eZFileHandler::flush ( )

Force a write of all buffered data.

Returns
true if succesful or false if something failed.
eZFileHandler::identifier ( )
Returns
the identifier of the current handler.
See Also
name

Referenced by eZForwardCompressionHandler\duplicate().

static eZFileHandler::instance (   $identifier,
  $filename = false,
  $mode = false,
  $binaryFile = true 
)
static

Returns a shared instance of the eZFileHandler class.

Returns the handler for the identifier $identifier. The parameters $filename, $mode and $binaryFile is passed to the handler.

Returns
false if the handler could not be created. $identifier if set is used to specify specific file handlers as defined in file.ini [FileSettings]Handlers. If $filename and later params are set, then file is opened straigt away.
Parameters
string | false$identifierGlobal eZFileHandler used if false
string | false$filename
string | false$modeset to 'r' if false
bool$binaryFileBinary or text mode, default true.
Returns
eZFileHandler|false

Referenced by eZCache\clearItem(), eZFSFileHandler\delete(), and eZFSFileHandler\fileDelete().

static eZFileHandler::isAvailable ( )
static
Returns
true if this handler can be used.
Note
The default implementation is to return true for all handlers.
eZFileHandler::isBinaryMode ( )
Returns
true if the file was opened in binary mode.

Referenced by eZGZIPZLIBCompressionHandler\doPasstrough().

eZFileHandler::isDirectory (   $filename = false)
Returns
true if $filename is a directory.
eZFileHandler::isExecutable (   $filename = false)
Returns
true if $filename is executable.
eZFileHandler::isFile (   $filename = false)
Returns
true if $filename is a file.
eZFileHandler::isLink (   $filename = false)
Returns
true if $filename is a link.
eZFileHandler::isOpen ( )
Returns
true if a file is opened, false otherwise.

Referenced by close(), eof(), flush(), open(), passtrough(), read(), rename(), rewind(), seek(), tell(), unlink(), and write().

eZFileHandler::isReadable (   $filename = false)
Returns
true if $filename is readable.
eZFileHandler::isWriteable (   $filename = false)
Returns
true if $filename is writeable.
static eZFileHandler::link (   $sourceFilename,
  $destinationFilename 
)
static

Creates a symbolic link to the file $sourceFilename on the destination $destinationFilename. This means that if someone tries to open $destinationFilename they will infact open $sourceFilename. If $destinationFilename is a directory then the filename is taken from $sourceFilename and appended to the destination. It will first try to rename the file and if that does not work copy the file and unlink.

Returns
true if sucessful or false if the copy failed.

Referenced by linkCopy().

static eZFileHandler::linkCopy (   $sourceFilename,
  $destinationFilename,
  $symbolicLink = true 
)
static

Links the file $sourceFilename to $destinationFilename. If $destinationFilename is a directory then the filename is taken from $sourceFilename and appended to the destination. It will use symbolic links for the operating system that support it and file copy for all others.

Parameters
$symbolicLinkif true then the files will be made as symbolic links, otherwise as hard links.
Returns
true if sucessful or false if the copy failed.

Referenced by eZImageManager\convert(), and eZFSFileHandler\fileLinkCopy().

eZFileHandler::mode ( )
Returns
the mode which was used to open the currently used file.

Referenced by eZGZIPZLIBCompressionHandler\doPasstrough(), and rename().

static eZFileHandler::move (   $sourceFilename,
  $destinationFilename 
)
static

Moves the file $sourceFilename to $destinationFilename. If $destinationFilename is a directory then the filename is taken from $sourceFilename and appended to the destination. It will first try to rename the file and if that does not work copy the file and unlink.

Returns
true if sucessful or false if the copy failed.

Referenced by eZFSFileHandler\move().

eZFileHandler::name ( )
Returns
the name of current handler.
See Also
identifier

Referenced by eZForwardCompressionHandler\duplicate().

eZFileHandler::open (   $filename,
  $mode,
  $binaryFile = true 
)

Tries to open the file $filename with mode $mode and returns the file resource if succesful.

Returns
false if the file could not be opened.
Parameters
$modeIf false the file will be opened in read mode using 'r'
$binaryFileIf true file will be opened in binary mode (default), otherwise text mode is used.
Note
Parameter $binaryFile will only have effect on the Windows operating system.

Referenced by rename().

eZFileHandler::passtrough (   $closeFile = true)

Passes the data from the file to the standard output.

Parameters
$closeFileIf true the file will be closed after output is done.
Returns
false if something failed.
eZFileHandler::read (   $length = false)

Reads up to $length bytes from file. Reading stops when $length has been read or EOF is reached, whichever comes first. If the optional parameter $length is not specified it will read bytes until EOF is reached.

Returns
a string or false if something fails.
eZFileHandler::rename (   $destinationFilename,
  $sourceFilename = false 
)

Renames the file $sourceFilename to $destinationFilename. If $sourceFilename is not supplied then filename() is used, it will also close the current file connection and reopen it again if was already open.

eZFileHandler::rewind ( )

Rewinds the file position to the beginning of the file.

Returns
0 if something went wrong.
eZFileHandler::seek (   $offset,
  $whence = SEEK_SET 
)

Seeks to position in file determined by $offset and $whence.

  • SEEK_SET - Set position equal to offset bytes.
  • SEEK_CUR - Set position to current location plus offset.
  • SEEK_END - Set position to end-of-file plus offset. (To move to a position before the end-of-file, you need to pass a negative value in offset.)
Note
Not all handlers supports all types for $whence
Returns
0 if succesful or -1 if something failed.
eZFileHandler::statistics (   $filename = false)
Returns
the statitistics for the file $filename.
static eZFileHandler::symlink (   $sourceFilename,
  $destinationFilename 
)
static

Creates a symbolic link to the file $sourceFilename on the destination $destinationFilename. This means that if someone tries to open $destinationFilename they will infact open $sourceFilename. If $destinationFilename is a directory then the filename is taken from $sourceFilename and appended to the destination. It will first try to rename the file and if that does not work copy the file and unlink.

Returns
true if sucessful or false if the copy failed.

Referenced by linkCopy().

eZFileHandler::tell ( )

Tells the current file position.

Returns
false if something failed.
eZFileHandler::unlink (   $filename = false)

Tries to unlink the file from the file system.

Referenced by doUnlink(), link(), move(), and symlink().

eZFileHandler::write (   $data,
  $length = false 
)

Writes the content of the string $data to the file. If optional $length parameter is supplied writing will stop after length is reached or the end of the string is reached, whichever comes first.

Returns
the number of bytes that was written.

Member Data Documentation

eZFileHandler::$IsBinary

Referenced by isBinaryMode().

eZFileHandler::$IsOpen

Referenced by isOpen().

eZFileHandler::$Mode

Referenced by mode().

eZFileHandler::$Name

Referenced by name().


The documentation for this class was generated from the following file: