7f4e3c39d6
This diff started off with trying to actually build `SplFileObject` since it was just stubbed out. But then I had to implement everything that extended from it since C++ classes can't extend PHP classes. And then it ballooend into what you see here. I actually think this is better in the long run, so that's why I kept going down this road. The only thing that doesn't work in pure PHP is `sscanf`. @mwilliams has a fix for that. We need variable args by reference. I implemented `RecursiveIteratorIterator` in a similar way to our C++ code instead of copying Zend. It translated to PHP a bit nicer. We still don't support the `RecursiveTreeIterator`, but I havn't come accross a need for that yet. I changed the implementation to actually use the `getChildren()` methods instead of peaking inside the `RecursiveDirectoryIterator`.
1041 linhas
33 KiB
PHP
1041 linhas
33 KiB
PHP
<?php
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/class.splfileinfo.php )
|
|
*
|
|
* The SplFileInfo class offers a high-level object oriented interface to
|
|
* information for an individual file.
|
|
*
|
|
*/
|
|
class SplFileInfo {
|
|
|
|
private $fileName;
|
|
private $fileClass;
|
|
private $infoClass;
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.construct.php )
|
|
*
|
|
* Creates a new SplFileInfo object for the file_name specified. The file
|
|
* does not need to exist, or be readable.
|
|
*
|
|
* @file_name mixed Path to the file.
|
|
*/
|
|
public function __construct($file_name) {
|
|
$this->setPathname($file_name);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getpath.php )
|
|
*
|
|
* Returns the path to the file, omitting the filename and any trailing
|
|
* slash.
|
|
*
|
|
* @return mixed Returns the path to the file.
|
|
*/
|
|
public function getPath() {
|
|
return dirname($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getfilename.php )
|
|
*
|
|
* Gets the filename without any path information.
|
|
*
|
|
* @return mixed The filename.
|
|
*/
|
|
public function getFilename() {
|
|
return $this->getBasename();
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getfileinfo.php )
|
|
*
|
|
* This method gets an SplFileInfo object for the referenced file.
|
|
*
|
|
* @class_name mixed Name of an SplFileInfo derived class to use.
|
|
*
|
|
* @return mixed An SplFileInfo object created for the file.
|
|
*/
|
|
public function getFileInfo($class_name = null) {
|
|
if (!$class_name) {
|
|
$class_name = $this->fileClass;
|
|
}
|
|
return new $class_name($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getbasename.php )
|
|
*
|
|
* This method returns the base name of the file, directory, or link
|
|
* without path info.
|
|
*
|
|
* @suffix mixed Optional suffix to omit from the base name returned.
|
|
*
|
|
* @return mixed Returns the base name without path information.
|
|
*/
|
|
public function getBasename($suffix = "") {
|
|
return basename($this->getPathname(), $suffix);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getpathname.php )
|
|
*
|
|
* Returns the path to the file.
|
|
*
|
|
* @return mixed The path to the file.
|
|
*/
|
|
public function getPathname() {
|
|
return $this->fileName;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getpathinfo.php )
|
|
*
|
|
* Gets an SplFileInfo object for the parent of the current file.
|
|
*
|
|
* @class_name mixed Name of an SplFileInfo derived class to use.
|
|
*
|
|
* @return mixed Returns an SplFileInfo object for the parent path of
|
|
* the file.
|
|
*/
|
|
public function getPathInfo($class_name = null) {
|
|
if (!$class_name) {
|
|
$class_name = $this->fileClass;
|
|
}
|
|
return new $class_name($this->getPath());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getperms.php )
|
|
*
|
|
* Gets the file permissions for the file.
|
|
*
|
|
* @return mixed Returns the file permissions.
|
|
*/
|
|
public function getPerms() {
|
|
return fileperms($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getinode.php )
|
|
*
|
|
* Gets the inode number for the filesystem object.
|
|
*
|
|
* @return mixed Returns the inode number for the filesystem object.
|
|
*/
|
|
public function getInode() {
|
|
return fileinode($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getsize.php )
|
|
*
|
|
* Returns the filesize in bytes for the file referenced.
|
|
*
|
|
* @return mixed The filesize in bytes.
|
|
*/
|
|
public function getSize() {
|
|
return filesize($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getowner.php )
|
|
*
|
|
* Gets the file owner. The owner ID is returned in numerical format.
|
|
*
|
|
* @return mixed The owner id in numerical format.
|
|
*/
|
|
public function getOwner() {
|
|
return fileowner($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getgroup.php )
|
|
*
|
|
* Gets the file group. The group ID is returned in numerical format.
|
|
*
|
|
* @return mixed The group id in numerical format.
|
|
*/
|
|
public function getGroup() {
|
|
return filegroup($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getatime.php )
|
|
*
|
|
* Gets the last access time for the file.
|
|
*
|
|
* @return mixed Returns the time the file was last accessed.
|
|
*/
|
|
public function getATime() {
|
|
return fileatime($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getmtime.php )
|
|
*
|
|
* Returns the time when the contents of the file were changed. The time
|
|
* returned is a Unix timestamp.
|
|
*
|
|
* @return mixed Returns the last modified time for the file, in a
|
|
* Unix timestamp.
|
|
*/
|
|
public function getMTime() {
|
|
return filemtime($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getctime.php )
|
|
*
|
|
* Returns the inode change time for the file. The time returned is a Unix
|
|
* timestamp.
|
|
*
|
|
* @return mixed The last change time, in a Unix timestamp.
|
|
*/
|
|
public function getCTime() {
|
|
return filectime($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.gettype.php )
|
|
*
|
|
* Returns the type of the file referenced.
|
|
*
|
|
* @return mixed A string representing the type of the entry. May be
|
|
* one of file, link, or dir
|
|
*/
|
|
public function getType() {
|
|
return filetype($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getextension.php )
|
|
*
|
|
* Retrieves the file extension.
|
|
*
|
|
* @return mixed Returns a string containing the file extension, or
|
|
* an empty string if the file has no extension.
|
|
*/
|
|
public function getExtension() {
|
|
return pathinfo($this->getPathname(), PATHINFO_EXTENSION);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.iswritable.php )
|
|
*
|
|
* Checks if the current entry is writable.
|
|
*
|
|
* @return mixed Returns TRUE if writable, FALSE otherwise;
|
|
*/
|
|
public function isWritable() {
|
|
return is_writable($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.isreadable.php )
|
|
*
|
|
* Check if the file is readable.
|
|
*
|
|
* @return mixed Returns TRUE if readable, FALSE otherwise.
|
|
*/
|
|
public function isReadable() {
|
|
return is_readable($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.isexecutable.php )
|
|
*
|
|
* Checks if the file is executable.
|
|
*
|
|
* @return mixed Returns TRUE if executable, FALSE otherwise.
|
|
*/
|
|
public function isExecutable() {
|
|
return is_executable($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.isfile.php )
|
|
*
|
|
* Checks if the file referenced by this SplFileInfo object exists and is
|
|
* a regular file.
|
|
*
|
|
* @return mixed Returns TRUE if the file exists and is a regular
|
|
* file (not a link), FALSE otherwise.
|
|
*/
|
|
public function isFile() {
|
|
return is_file($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.isdir.php )
|
|
*
|
|
* This method can be used to determine if the file is a directory.
|
|
*
|
|
* @return mixed Returns TRUE if a directory, FALSE otherwise.
|
|
*/
|
|
public function isDir() {
|
|
return is_dir($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.islink.php )
|
|
*
|
|
* Use this method to check if the file referenced by the SplFileInfo
|
|
* object is a link.
|
|
*
|
|
* @return mixed Returns TRUE if the file is a link, FALSE otherwise.
|
|
*/
|
|
public function isLink() {
|
|
return is_link($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getlinktarget.php )
|
|
*
|
|
* Gets the target of a filesystem link.
|
|
*
|
|
* The target may not be the real path on the filesystem. Use
|
|
* SplFileInfo::getRealPath() to determine the true path on the filesystem.
|
|
*
|
|
* @return mixed Returns the target of the filesystem link.
|
|
*/
|
|
public function getLinkTarget() {
|
|
$link = @readlink($this->getPathname());
|
|
if ($link === false) {
|
|
throw new Exception(
|
|
'Unable to read link '.$this->getPathname()
|
|
);
|
|
}
|
|
return $link;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.getrealpath.php )
|
|
*
|
|
* This method expands all symbolic links, resolves relative references
|
|
* and returns the real path to the file.
|
|
*
|
|
* @return mixed Returns the path to the file.
|
|
*/
|
|
public function getRealPath() {
|
|
return realpath($this->getPathname());
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.tostring.php )
|
|
*
|
|
* This method will return the file name of the referenced file.
|
|
*
|
|
* @return mixed Returns the path to the file.
|
|
*/
|
|
public function __toString() {
|
|
return $this->getPathname();
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.openfile.php )
|
|
*
|
|
* Creates an SplFileObject object of the file. This is useful because
|
|
* SplFileObject contains additional methods for manipulating the file
|
|
* whereas SplFileInfo is only useful for gaining information, like whether
|
|
* the file is writable.
|
|
*
|
|
* @mode mixed The mode for opening the file. See the fopen()
|
|
* documentation for descriptions of possible modes.
|
|
* The default is read only.
|
|
* @use_include_path
|
|
* mixed When set to TRUE, the filename is also searched for
|
|
* within the include_path
|
|
* @context mixed Refer to the context section of the manual for a
|
|
* description of contexts.
|
|
*
|
|
* @return mixed The opened file as an SplFileObject object.
|
|
*/
|
|
public function openFile($mode = 'r', $use_include_path = false,
|
|
$context = null) {
|
|
$class_name = $this->fileClass;
|
|
return new $class_name(
|
|
$this->getPathname(),
|
|
$mode,
|
|
$use_include_path,
|
|
$context
|
|
);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.setfileclass.php )
|
|
*
|
|
* Set the class name which SplFileInfo will use to open files with when
|
|
* openFile() is called. The class name passed to this method must be
|
|
* derived from SplFileObject.
|
|
*
|
|
* @class_name mixed The class name to use when openFile() is called.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function setFileClass($class_name = "SplFileObject") {
|
|
$this->fileClass = $class_name;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileinfo.setinfoclass.php )
|
|
*
|
|
* Use this method to set a custom class which will be used when
|
|
* getFileInfo and getPathInfo are called. The class name passed to this
|
|
* method must be derived from SplFileInfo.
|
|
*
|
|
* @class_name mixed The class name to use.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function setInfoClass($class_name = "SplFileInfo") {
|
|
$this->infoClass = $class_name;
|
|
}
|
|
|
|
protected function setPathname($file_name) {
|
|
if ($file_name !== false) {
|
|
$file_name = rtrim($file_name, '/');
|
|
}
|
|
$this->fileName = $file_name;
|
|
}
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/class.splfileobject.php )
|
|
*
|
|
* The SplFileObject class offers an object oriented interface for a file.
|
|
*
|
|
*/
|
|
class SplFileObject extends SplFileInfo
|
|
implements RecursiveIterator, SeekableIterator {
|
|
|
|
const DROP_NEW_LINE = 1;
|
|
const READ_AHEAD = 2;
|
|
const SKIP_EMPTY = 4;
|
|
const READ_CSV = 8;
|
|
|
|
private $delimiter = ',';
|
|
private $enclosure = '"';
|
|
private $escape = '\\';
|
|
private $flags;
|
|
private $maxLineLen = 0;
|
|
private $currentLineNum = 0;
|
|
private $rsrc;
|
|
private $currentLine = false;
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.construct.php )
|
|
*
|
|
* Construct a new file object.
|
|
*
|
|
* @filename mixed The file to read. TipA URL can be used as a filename
|
|
* with this function if the fopen wrappers have been
|
|
* enabled. See fopen() for more details on how to
|
|
* specify the filename. See the Supported Protocols
|
|
* and Wrappers for links to information about what
|
|
* abilities the various wrappers have, notes on their
|
|
* usage, and information on any predefined variables
|
|
* they may provide.
|
|
* @open_mode mixed The mode in which to open the file. See fopen() for
|
|
* a list of allowed modes.
|
|
* @use_include_path
|
|
* mixed Whether to search in the include_path for filename.
|
|
* @context mixed A valid context resource created with
|
|
* stream_context_create().
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function __construct($filename, $open_mode = 'r',
|
|
$use_include_path = false,
|
|
$context = null) {
|
|
parent::__construct($filename);
|
|
if (!is_string($open_mode)) {
|
|
throw new Exception(
|
|
'SplFileObject::__construct() expects parameter 2 to be string, '.
|
|
gettype($open_mode).' given'
|
|
);
|
|
}
|
|
$this->rsrc = fopen($filename, $open_mode, $use_include_path, $context);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.eof.php )
|
|
*
|
|
* Determine whether the end of file has been reached
|
|
*
|
|
* @return mixed Returns TRUE if file is at EOF, FALSE otherwise.
|
|
*/
|
|
public function eof() {
|
|
return feof($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fflush.php )
|
|
*
|
|
* Forces a write of all buffered output to the file.
|
|
*
|
|
* @return mixed Returns TRUE on success or FALSE on failure.
|
|
*/
|
|
public function fflush() {
|
|
return fflush($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fgetc.php )
|
|
*
|
|
* Gets a character from the file.
|
|
*
|
|
* @return mixed Returns a string containing a single character read
|
|
* from the file or FALSE on EOF. WarningThis function
|
|
* may return Boolean FALSE, but may also return a
|
|
* non-Boolean value which evaluates to FALSE. Please
|
|
* read the section on Booleans for more information.
|
|
* Use the === operator for testing the return value of
|
|
* this function.
|
|
*/
|
|
public function fgetc() {
|
|
return fgetc($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fgetcsv.php )
|
|
*
|
|
* Gets a line from the file which is in CSV format and returns an array
|
|
* containing the fields read.
|
|
*
|
|
* @delimiter mixed The field delimiter (one character only). Defaults
|
|
* as a comma or the value set using
|
|
* SplFileObject::setCsvControl().
|
|
* @enclosure mixed The field enclosure character (one character only).
|
|
* Defaults as a double quotation mark or the value set
|
|
* using SplFileObject::setCsvControl().
|
|
* @escape mixed The escape character (one character only). Defaults
|
|
* as a backslash (\) or the value set using
|
|
* SplFileObject::setCsvControl().
|
|
*
|
|
* @return mixed Returns an indexed array containing the fields read,
|
|
* or FALSE on error.
|
|
*
|
|
* A blank line in a CSV file will be returned as an
|
|
* array comprising a single NULL field unless using
|
|
* SplFileObject::SKIP_EMPTY |
|
|
* SplFileObject::DROP_NEW_LINE, in which case empty
|
|
* lines are skipped.
|
|
*/
|
|
public function fgetcsv(
|
|
$delimiter = null,
|
|
$enclosure = null,
|
|
$escape = null) {
|
|
|
|
if (!$delimiter) {
|
|
$delimiter = $this->delimiter;
|
|
}
|
|
if (!$enclosure) {
|
|
$enclosure = $this->enclosure;
|
|
}
|
|
if (!$escape) {
|
|
$escape = $this->escape;
|
|
}
|
|
|
|
return fgetcsv(
|
|
$this->rsrc,
|
|
$this->maxLineLen,
|
|
$delimiter,
|
|
$enclosure,
|
|
$escape
|
|
);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fgets.php )
|
|
*
|
|
* Gets a line from the file.
|
|
*
|
|
* @return mixed Returns a string containing the next line from the
|
|
* file, or FALSE on error.
|
|
*/
|
|
public function fgets() {
|
|
$line = fgets($this->rsrc);
|
|
if ($this->flags & self::DROP_NEW_LINE) {
|
|
$line = rtrim($line);
|
|
}
|
|
return $line;
|
|
}
|
|
|
|
public function getCurrentLine() {
|
|
return $this->fgets();
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fgetss.php )
|
|
*
|
|
* Identical to SplFileObject::fgets(), except that
|
|
* SplFileObject::fgetss() attempts to strip any HTML and PHP tags from the
|
|
* text it reads.
|
|
*
|
|
* @allowable_tags
|
|
* mixed Optional parameter to specify tags which should not
|
|
* be stripped.
|
|
*
|
|
* @return mixed Returns a string containing the next line of the
|
|
* file with HTML and PHP code stripped, or FALSE on
|
|
* error.
|
|
*/
|
|
public function fgetss($allowable_tags = null) {
|
|
return fgetss($this->rsrc, $this->maxLineLen, $allowable_tags);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.flock.php )
|
|
*
|
|
* Locks or unlocks the file in the same portable way as flock().
|
|
*
|
|
* @operation mixed operation is one of the following: LOCK_SH to
|
|
* acquire a shared lock (reader). LOCK_EX to acquire
|
|
* an exclusive lock (writer). LOCK_UN to release a
|
|
* lock (shared or exclusive). LOCK_NB to not block
|
|
* while locking (not supported on Windows).
|
|
* @wouldblock mixed Set to TRUE if the lock would block (EWOULDBLOCK
|
|
* errno condition).
|
|
*
|
|
* @return mixed Returns TRUE on success or FALSE on failure.
|
|
*/
|
|
public function flock($operation, &$wouldblock) {
|
|
return flock($this->rsrc, $operation, $wouldblock);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fpassthru.php )
|
|
*
|
|
* Reads to EOF on the given file pointer from the current position and
|
|
* writes the results to the output buffer.
|
|
*
|
|
* You may need to call SplFileObject::rewind() to reset the file pointer
|
|
* to the beginning of the file if you have already written data to the
|
|
* file.
|
|
*
|
|
* @return mixed Returns the number of characters read from handle
|
|
* and passed through to the output.
|
|
*/
|
|
public function fpassthru() {
|
|
return fpassthru($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fputcsv.php )
|
|
*
|
|
* Writes the fields array to the file as a CSV line.
|
|
*
|
|
* @fields mixed An array of values.
|
|
* @delimiter mixed The optional delimiter parameter sets the field
|
|
* delimiter (one character only).
|
|
* @enclosure mixed The optional enclosure parameter sets the field
|
|
* enclosure (one character only).
|
|
*
|
|
* @return mixed Returns the length of the written string or FALSE on
|
|
* failure.
|
|
*
|
|
* Returns FALSE, and does not write the CSV line to
|
|
* the file, if the delimiter or enclosure parameter is
|
|
* not a single character.
|
|
*/
|
|
public function fputcsv($fields, $delimiter = null, $enclosure = null) {
|
|
if (!$delimiter) {
|
|
$delimiter = $this->delimiter;
|
|
}
|
|
if (!$enclosure) {
|
|
$enclosure = $this->enclosure;
|
|
}
|
|
|
|
return fputcsv(
|
|
$this->rsrc,
|
|
$fields,
|
|
$delimiter,
|
|
$enclosure
|
|
);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fscanf.php )
|
|
*
|
|
* Reads a line from the file and interprets it according to the specified
|
|
* format, which is described in the documentation for sprintf().
|
|
*
|
|
* Any whitespace in the format string matches any whitespace in the line
|
|
* from the file. This means that even a tab \t in the format string can
|
|
* match a single space character in the input stream.
|
|
*
|
|
* @format mixed The specified format as described in the sprintf()
|
|
* documentation.
|
|
*
|
|
* @return mixed If only one parameter is passed to this method, the
|
|
* values parsed will be returned as an array.
|
|
* Otherwise, if optional parameters are passed, the
|
|
* function will return the number of assigned values.
|
|
* The optional parameters must be passed by reference.
|
|
*/
|
|
public function fscanf($format) {
|
|
$argv = array($this->rsrc);
|
|
for ($i = 0; $i < func_num_args(); $i++) {
|
|
$argv[] = func_get_arg($i);
|
|
}
|
|
return call_user_func_array('fscanf', $argv);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fseek.php )
|
|
*
|
|
* Seek to a position in the file measured in bytes from the beginning of
|
|
* the file, obtained by adding offset to the position specified by whence.
|
|
*
|
|
* @offset mixed The offset. A negative value can be used to move
|
|
* backwards through the file which is useful when
|
|
* SEEK_END is used as the whence value.
|
|
* @whence mixed whence values are: 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.
|
|
*
|
|
* If whence is not specified, it is assumed to be
|
|
* SEEK_SET.
|
|
*
|
|
* @return mixed Returns 0 if the seek was successful, -1 otherwise.
|
|
* Note that seeking past EOF is not considered an
|
|
* error.
|
|
*/
|
|
public function fseek($offset, $whence) {
|
|
return fseek($this->rsrc, $offset, $whence);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fstat.php )
|
|
*
|
|
* Gathers the statistics of the file. Behaves identically to fstat().
|
|
*
|
|
* @return mixed Returns an array with the statistics of the file;
|
|
* the format of the array is described in detail on
|
|
* the stat() manual page.
|
|
*/
|
|
public function fstat() {
|
|
return fstat($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.ftell.php )
|
|
*
|
|
* Returns the position of the file pointer which represents the current
|
|
* offset in the file stream.
|
|
*
|
|
* @return mixed Returns the position of the file pointer as an
|
|
* integer, or FALSE on error.
|
|
*/
|
|
public function ftell() {
|
|
return ftell($this->rsrc);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.ftruncate.php )
|
|
*
|
|
* Truncates the file to size bytes.
|
|
*
|
|
* @size mixed The size to truncate to.
|
|
*
|
|
* If size is larger than the file it is extended with
|
|
* null bytes.
|
|
*
|
|
* If size is smaller than the file, the extra data
|
|
* will be lost.
|
|
*
|
|
* @return mixed Returns TRUE on success or FALSE on failure.
|
|
*/
|
|
public function ftruncate($size) {
|
|
return ftruncate($this->rsrc, $size);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.fwrite.php )
|
|
*
|
|
* Writes the contents of string to the file
|
|
*
|
|
* @str mixed The string to be written to the file.
|
|
* @length mixed If the length argument is given, writing will stop
|
|
* after length bytes have been written or the end of
|
|
* string is reached, whichever comes first.
|
|
*
|
|
* @return mixed Returns the number of bytes written, or NULL on
|
|
* error.
|
|
*/
|
|
public function fwrite($str, $length) {
|
|
return fwrite($this->rsrc, $str, $length);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.getchildren.php )
|
|
*
|
|
* An SplFileObject does not have children so this method returns NULL.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function getChildren() {
|
|
return null; // An SplFileOjbect does not have children
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.getcsvcontrol.php
|
|
* )
|
|
*
|
|
* Gets the delimiter and enclosure character used for parsing CSV fields.
|
|
*
|
|
* @return mixed Returns an indexed array containing the delimiter
|
|
* and enclosure character.
|
|
*/
|
|
public function getCsvControl() {
|
|
return array($this->delimiter, $this->enclosure);
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.getflags.php )
|
|
*
|
|
* Gets the flags set for an instance of SplFileObject as an integer.
|
|
*
|
|
* @return mixed Returns an integer representing the flags.
|
|
*/
|
|
public function getFlags() {
|
|
return $this->flags;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.getmaxlinelen.php
|
|
* )
|
|
*
|
|
* Gets the maximum line length as set by SplFileObject::setMaxLineLen().
|
|
*
|
|
* @return mixed Returns the maximum line length if one has been set
|
|
* with SplFileObject::setMaxLineLen(), default is 0.
|
|
*/
|
|
public function getMaxLineLen() {
|
|
return $this->maxLineLen;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.haschildren.php )
|
|
*
|
|
* An SplFileObject does not have children so this method always return
|
|
* FALSE.
|
|
*
|
|
* @return mixed Returns FALSE
|
|
*/
|
|
public function hasChildren() {
|
|
return false; // An SplFileOjbect does not have children
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.setcsvcontrol.php
|
|
* )
|
|
*
|
|
* Sets the delimiter and enclosure character for parsing CSV fields.
|
|
*
|
|
* @delimiter mixed The field delimiter (one character only).
|
|
* @enclosure mixed The field enclosure character (one character only).
|
|
* @escape mixed The field escape character (one character only).
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function setCsvControl(
|
|
$delimiter = ",",
|
|
$enclosure = "\"",
|
|
$escape = "\\") {
|
|
|
|
$this->delimiter = $delimiter;
|
|
$this->enclosure = $enclosure;
|
|
$this->escape = $escape;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.setflags.php )
|
|
*
|
|
* Sets the flags to be used by the SplFileObject.
|
|
*
|
|
* @flags mixed Bit mask of the flags to set. See SplFileObject
|
|
* constants for the available flags.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function setFlags($flags) {
|
|
$this->flags = $flags;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.setmaxlinelen.php
|
|
* )
|
|
*
|
|
* Sets the maximum length of a line to be read.
|
|
*
|
|
* @max_len mixed The maximum length of a line.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function setMaxLineLen($max_len) {
|
|
if ($max_len < 0) {
|
|
throw new DomainException(
|
|
'Maximum line length must be greater than or equal zero'
|
|
);
|
|
}
|
|
$this->maxLineLen = $max_len;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.current.php )
|
|
*
|
|
* Retrieves the current line of the file.
|
|
*
|
|
* @return mixed Retrieves the current line of the file. If the
|
|
* SplFileObject::READ_CSV flag is set, this method
|
|
* returns an array containing the current line parsed
|
|
* as CSV data.
|
|
*/
|
|
public function current() {
|
|
if ($this->currentLine === false) {
|
|
$this->currentLine = $this->fgets();
|
|
}
|
|
return $this->currentLine;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.key.php )
|
|
*
|
|
* Gets the current line number.
|
|
*
|
|
* This number may not reflect the actual line number in the file if
|
|
* SplFileObject::setMaxLineLen() is used to read fixed lengths of the
|
|
* file.
|
|
*
|
|
* @return mixed Returns the current line number.
|
|
*/
|
|
public function key() {
|
|
return $this->currentLineNum;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.next.php )
|
|
*
|
|
* Moves ahead to the next line in the file.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function next() {
|
|
$this->currentLine = false;
|
|
$this->currentLineNum++;
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.rewind.php )
|
|
*
|
|
* Rewinds the file back to the first line.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function rewind() {
|
|
rewind($this->rsrc);
|
|
$this->currentLineNum = 0;
|
|
$this->currentLine = false;
|
|
if ($this->flags & self::READ_AHEAD) {
|
|
$this->current();
|
|
}
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.seek.php )
|
|
*
|
|
* Seek to specified line in the file.
|
|
*
|
|
* @line_pos mixed The zero-based line number to seek to.
|
|
*
|
|
* @return mixed No value is returned.
|
|
*/
|
|
public function seek($line_pos) {
|
|
$this->rewind();
|
|
for ($i = 0; $i < $line_pos; $i++) {
|
|
$this->current();
|
|
$this->next();
|
|
}
|
|
$this->current();
|
|
}
|
|
|
|
// This doc comment block generated by idl/sysdoc.php
|
|
/**
|
|
* ( excerpt from http://php.net/manual/en/splfileobject.valid.php )
|
|
*
|
|
* Check whether EOF has been reached.
|
|
*
|
|
* @return mixed Returns TRUE if not reached EOF, FALSE otherwise.
|
|
*/
|
|
public function valid() {
|
|
if ($this->flags & self::READ_AHEAD) {
|
|
return $this->current() !== false;
|
|
}
|
|
return !$this->eof();
|
|
}
|
|
}
|