summaryrefslogtreecommitdiff
path: root/ext/spl/internal/splfileobject.inc
diff options
context:
space:
mode:
authorSVN Migration <svn@php.net>2006-10-15 21:09:28 +0000
committerSVN Migration <svn@php.net>2006-10-15 21:09:28 +0000
commit88ec761548b66f58acc1a86cdd0fc164ca925476 (patch)
treed0af978fa00d83bb1d82c613f66477fbd6bb18aa /ext/spl/internal/splfileobject.inc
parent268984b4787e797db6054313fc9ba3b9e845306e (diff)
downloadphp-git-PECL_OPENSSL.tar.gz
This commit was manufactured by cvs2svn to create branch 'PECL_OPENSSL'.PECL_OPENSSL
Diffstat (limited to 'ext/spl/internal/splfileobject.inc')
-rwxr-xr-xext/spl/internal/splfileobject.inc385
1 files changed, 0 insertions, 385 deletions
diff --git a/ext/spl/internal/splfileobject.inc b/ext/spl/internal/splfileobject.inc
deleted file mode 100755
index 08b2d091dd..0000000000
--- a/ext/spl/internal/splfileobject.inc
+++ /dev/null
@@ -1,385 +0,0 @@
-<?php
-
-/** @file splfileobject.inc
- * @ingroup SPL
- * @brief class FileObject
- * @author Marcus Boerger
- * @date 2003 - 2006
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Object representation for any stream
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- */
-class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator
-{
- /** Flag: wheter to suppress new lines */
- const DROP_NEW_LINE = 0x00000001;
-
- private $fp;
- private $fname;
- private $line = NULL;
- private $lnum = 0;
- private $max_len = 0;
- private $flags = 0;
- private $delimiter= ',';
- private $enclosure= '"';
-
- /**
- * Constructs a new file object
- *
- * @param $file_name The name of the stream to open
- * @param $open_mode The file open mode
- * @param $use_include_path Whether to search in include paths
- * @param $context A stream context
- * @throw RuntimeException If file cannot be opened (e.g. insufficient
- * access rights).
- */
- function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL)
- {
- $this->fp = fopen($file_name, $open_mode, $use_include_path, $context);
- if (!$this->fp)
- {
- throw new RuntimeException("Cannot open file $file_name");
- }
- $this->fname = $file_name;
- }
-
- /**
- * @return the filename as specified in the constructor
- */
- function getFilename()
- {
- return $this->fname;
- }
-
- /**
- * @return whether the end of the stream is reached
- */
- function eof()
- {
- return eof($this->fp);
- }
-
- /** increase current line number
- * @return next line from stream
- */
- function fgets()
- {
- $this->freeLine();
- $this->lnum++;
- $buf = fgets($this->fp, $this->max_len);
-
- return $buf;
- }
-
- /**
- * @param delimiter character used as field separator
- * @param enclosure end of
- * @return array containing read data
- */
- function fgetcsv($delimiter = NULL, $enclosure = NULL)
- {
- $this->freeLine();
- $this->lnum++;
- switch(fun_num_args())
- {
- case 0:
- $delimiter = $this->delimiter;
- case 1:
- $enclosure = $this->enclosure;
- default:
- case 2:
- break;
- }
- return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure);
- }
-
- /**
- * Set the delimiter and enclosure character used in fgetcsv
- *
- * @param delimiter new delimiter, defaults to ','
- * @param enclosure new enclosure, defaults to '"'
- */
- function setCsvControl($delimiter = ';', $enclosure = '"')
- {
- $this->delimiter = $delimiter;
- $this->enclosure = $enclosure;
- }
-
- /**
- * @return array(delimiter, enclosure) as used in fgetcsv
- */
- function getCsvControl($delimiter = ',', $enclosure = '"')
- {
- return array($this->delimiter, $this->enclosure);
- }
-
- /**
- * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB)
- * @retval $wouldblock whether the operation would block
- */
- function flock($operation, &$wouldblock)
- {
- return flock($this->fp, $operation, $wouldblock);
- }
-
- /**
- * Flush current data
- * @return success or failure
- */
- function fflush()
- {
- return fflush($this->fp);
- }
-
- /**
- * @return current file position
- */
- function ftell()
- {
- return ftell($this->fp);
- }
-
- /**
- * @param pos new file position
- * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END)
- * @return Upon success, returns 0; otherwise, returns -1. Note that
- * seeking past EOF is not considered an error.
- */
- function fseek($pos, $whence = SEEK_SET)
- {
- return fseek($this->fp, $pos, $whence);
- }
-
- /**
- * @return next char from file
- * @note a new line character does not increase $this->lnum
- */
- function fgetc()
- {
- $this->freeLine();
- $c = fgetc($this->fp);
- if ($c == '\n') {
- $this->lnum++;
- }
- }
-
- /** Read and return remaining part of stream
- * @return size of remaining part passed through
- */
- function fpassthru()
- {
- return fpassthru($this->fp);
- }
-
- /** Get a line from the file and strip HTML tags
- * @param $allowable_tags tags to keep in the string
- */
- function fgetss($allowable_tags = NULL)
- {
- return fgetss($this->fp, $allowable_tags);
- }
-
- /** Scan the next line
- * @param $format string specifying format to parse
- */
- function fscanf($format /* , ... */)
- {
- $this->freeLine();
- $this->lnum++;
- return fscanf($this->fp, $format /* , ... */);
- }
-
- /**
- * @param $str to write
- * @param $length maximum line length to write
- */
- function fwrite($str, $length = NULL)
- {
- return fwrite($this->fp, $length);
- }
-
- /**
- * @return array of file stat information
- */
- function fstat()
- {
- return fstat($this->fp);
- }
-
- /**
- * @param $size new size to truncate file to
- */
- function ftruncate($size)
- {
- return ftruncate($this->fp, $size);
- }
-
- /**
- * @param $flags new flag set
- */
- function setFlags($flags)
- {
- $this->flags = $flags;
- }
-
- /**
- * @return current set of flags
- */
- function getFlags()
- {
- return $this->flags;
- }
-
- /**
- * @param $max_len set the maximum line length read
- */
- function setMaxLineLen($max_len)
- {
- $this->max_len = $max_len;
- }
-
- /**
- * @return current setting for max line
- */
- function getMaxLineLen()
- {
- return $this->max_len;
- }
-
- /**
- * @return false
- */
- function hasChildren()
- {
- return false;
- }
-
- /**
- * @return false
- */
- function getChildren()
- {
- return NULL;
- }
-
- /**
- * Invalidate current line buffer and set line number to 0.
- */
- function rewind()
- {
- $this->freeLine();
- $this->lnum = 0;
- }
-
- /**
- * @return whether more data can be read
- */
- function valid()
- {
- return !$this->eof();
- }
-
- /**
- * @note Fill current line buffer if not done yet.
- * @return line buffer
- */
- function current()
- {
- if (is_null($this->line))
- {
- $this->line = getCurrentLine();
- }
- return $this->line;
- }
-
- /**
- * @return line number
- * @note fgetc() will increase the line number when reaing a new line char.
- * This has the effect key() called on a read a new line will already
- * return the increased line number.
- * @note Line counting works as long as you only read the file and do not
- * use fseek().
- */
- function key()
- {
- return $this->lnum;
- }
-
- /** Invalidate current line buffer.
- */
- function next()
- {
- $this->freeLine();
- }
-
- /**
- * @return next line read from file and increase the line counter
- */
- private function readLine()
- {
- if ($this->eof())
- {
- $this->freeLine();
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- if ($this->line) {
- $this->lnum++;
- }
- $this->freeLine();
- $this->line = fgets($this->fp, $this->max_len);
- return $this->line;
- }
-
- /**
- * Free the current line buffer and increment the line counter
- */
- private function freeLine()
- {
- if ($this->line) {
- $this->line = NULL;
- }
- }
-
- /*
- * @note If you DO overload this function key() and current() will increment
- * $this->lnum automatically. If not then function reaLine() will do
- * that for you.
- */
- function getCurrentLine()
- {
- $this->freeLine();
- if ($this->eof())
- {
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- $this->readLine();
- }
-
- /**
- * @return current line
- */
- function __toString()
- {
- return current();
- }
-
- /**
- * @param $line_pos Seek to this line
- */
- function seek($line_pos)
- {
- $this->rewind();
- while($this->lnum < $line_pos && !$this->eof())
- {
- $this->getCurrentLine();
- }
- }
-}
-
-?>