php-src/ext/spl/spl.php

856 lines
23 KiB
PHP
Raw Normal View History

2003-05-02 07:28:28 +08:00
<?php
2004-11-02 01:05:45 +08:00
/** @file spl.php
* @ingroup SPL
* @brief Documentation of internal classes and interfaces
*
* SPL - Standard PHP Library
*
2005-02-09 03:05:25 +08:00
* (c) Marcus Boerger, 2003 - 2005
*/
2004-11-02 01:05:45 +08:00
/** @mainpage SPL - Standard PHP Library
2004-05-07 06:55:25 +08:00
*
* SPL - Standard PHP Library
2003-05-02 07:28:28 +08:00
*
2004-11-01 23:50:25 +08:00
* SPL is a collection of interfaces and classes that are meant to solve
2004-11-02 02:01:06 +08:00
* standard problems and implements some efficient data access interfaces
* and classes. You'll find the classes documented using php code in the
* file spl.php or in corresponding .inc files in subdirectories examples
* and internal. Based on the internal implementations or the files in the
* examples subdirectory there are also some .php files to experiment with.
*
* The .inc files are not included automatically because they are sooner or
* later integrated into the extension. That means that you either need to
* put the code of examples/autoload.inc into your autoprepend file or that
* you have to point your ini setting auto_prepend_file to that file.
*
* Below is a list of interfaces/classes already availabel natively through
* the SPL extension grouped by category.
*
* 1) Iterators
*
* SPL offers some advanced iterator algorithms:
*
* - interface RecursiveIterator implements Iterator
* - interface OuterIterator extends Iterator
* - class RecursiveIteratorIterator implements OuterIterator
* - abstract class FilterIterator implements OuterIterator
* - class ParentIterator extends FilterIterator implements RecursiveIterator
* - interface SeekableIterator implements Iterator
* - class LimitIterator implements OuterIterator
* - class CachingIterator implements OuterIterator
* - class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator
* - class IteratorIterator implements OuterIterator
* - class NoRewindIterator implements OuterIterator
* - class EmptyIterator implements Iterator
* - class InfiniteIterator extends IteratorIterator
* - class AppendIterator implements OuterIterator
*
* 2) Directories and Files
2004-11-02 02:01:06 +08:00
*
* SPL offers two advanced directory and file handling classes:
2004-11-02 02:01:06 +08:00
*
* - class DirectoryIterator implements Iterator
* - class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator
* - class SplFileObject implements RecursiveIterator, SeekableIterator
2004-11-02 02:01:06 +08:00
*
* 3) XML
*
* SPL offers an advanced XML handling class:
*
* - class SimpleXMLIterator extends simplexml_element implements RecursiveIterator
2004-11-02 02:01:06 +08:00
*
* 4) Array Overloading
*
* SPL offers advanced Array overloading:
*
* - class ArrayObject implements IteratorAggregate
* - class ArrayIterator implements Iterator
2005-02-09 04:42:48 +08:00
*
* As the above suggest an ArrayObject creates an ArrayIterator when it comes to
* iteration (e.g. ArrayObject instance used inside foreach).
2004-11-02 02:01:06 +08:00
*
* 5) Counting
*
2005-02-09 03:05:25 +08:00
* - interface Countable allows to hook into the standard array function count().
2004-11-02 02:01:06 +08:00
*
2005-05-03 20:09:26 +08:00
* 6) Exception%s
2004-11-02 02:01:06 +08:00
*
2005-05-03 20:09:26 +08:00
* SPL provides a set of standard Exception classes each meant to indicate a
2004-11-02 02:01:06 +08:00
* certain problem type.
*
* - class LogicException extends Exception
* - class BadFunctionCallException extends LogicException
* - class BadMethodCallException extends BadFunctionCallException
* - class DomainException extends LogicException
* - class InvalidArgumentException extends LogicException
* - class LengthException extends LogicException
* - class OutOfRangeException extends LogicException
* - class RuntimeException extends Exception
* - class OutOfBoundsException extends RuntimeException
* - class OverflowException extends RuntimeException
* - class RangeException extends RuntimeException
* - class UnderflowException extends RuntimeException
2005-02-09 04:42:48 +08:00
*
* 7) Observer
*
* SPL suggests a standard way of implementing the observer pattern.
*
* - interface SplObserver
* - interface SplSubject
* - class SplObjectStorage
2004-11-02 02:01:06 +08:00
*
* Some articles about SPL:
* - <a href="http://www.sitepoint.com/article/php5-standard-library/1">Introducing PHP 5's Standard Library</a>
2005-05-03 20:09:26 +08:00
* - <a href="http://www.ramikayyali.com/archives/2005/02/25/iterators">Iterators in PHP5</a>
* - <a href="http://www.phpriot.com/d/articles/php/oop/oop-with-spl-php-5-1/index.html">Advanced OOP with SPL in PHP 5</a>
* - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-1/">The Standard PHP Library, Part 1</a>
2005-05-03 20:09:26 +08:00
* - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-2/">The Standard PHP Library, Part 2</a>
* - <a href="http://www.wiki.cc/php/SPL">SPL on PHP Wiki</a>
* - <a href="http://www.professionelle-softwareentwicklung-mit-php5.de/erste_auflage/oop.iterators.spl.html">Die Standard PHP Library (SPL) [german]</a>
*
2005-05-03 20:09:26 +08:00
* Talks on SPL:
* - SPL for the masses <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pdf">[pdf]</a>
* - Debug session 1 <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_1.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_1.pdf">[pdf]</a>
* - Debug session 2 <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_2.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_iterator_debug_session_2.pdf">[pdf]</a>
* - From engine overloading to SPL <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pps">[pps]</a>, <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pdf">[pdf]</a>
2004-11-01 23:50:25 +08:00
*
* You can download this documentation as a chm file
* <a href="http://php.net/~helly/php/ext/spl/spl.chm">here</a>.
*
2005-02-09 03:05:25 +08:00
* (c) Marcus Boerger, 2003 - 2005
2003-05-02 07:28:28 +08:00
*/
2004-11-01 23:50:25 +08:00
/** @defgroup ZendEngine Zend engine classes
*
* The classes and interfaces in this group are contained in the c-code of
* PHP's Zend engine.
*/
/** @defgroup SPL Internal classes
2004-05-08 20:26:28 +08:00
*
* The classes and interfaces in this group are contained in the c-code of
* ext/SPL.
*/
2004-11-01 23:50:25 +08:00
/** @defgroup Examples Example classes
2004-05-08 20:26:28 +08:00
*
* The classes and interfaces in this group are contained as PHP code in the
* examples subdirectory of ext/SPL. Sooner or later they will be moved to
* c-code.
*/
2004-11-01 23:50:25 +08:00
/** @ingroup ZendEngine
* @brief Basic Exception class.
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-11-01 23:50:25 +08:00
*/
class Exception
{
/** The exception message */
protected $message;
/** The string represenations as generated during construction */
private $string;
/** The code passed to the constructor */
protected $code;
/** The file name where the exception was instantiated */
protected $file;
/** The line number where the exception was instantiated */
protected $line;
/** The stack trace */
private $trace;
/** Prevent clone
*/
2004-11-02 00:31:19 +08:00
final private function __clone() {}
2004-11-01 23:50:25 +08:00
2004-11-02 00:31:19 +08:00
/** Construct an exception
*
* @param $message Some text describing the exception
* @param $code Some code describing the exception
2004-11-01 23:50:25 +08:00
*/
2004-11-02 00:31:19 +08:00
function __construct($message = NULL, $code = 0) {
if (func_num_args()) {
$this->message = $message;
}
$this->code = $code;
$this->file = __FILE__; // of throw clause
$this->line = __LINE__; // of throw clause
$this->trace = debug_backtrace();
$this->string = StringFormat($this);
}
2004-11-01 23:50:25 +08:00
/** @return the message passed to the constructor
*/
2004-11-02 00:31:19 +08:00
final public function getMessage()
{
return $this->message;
}
2004-11-01 23:50:25 +08:00
/** @return the code passed to the constructor
*/
2004-11-02 00:31:19 +08:00
final public function getCode()
{
return $this->code;
}
2004-11-01 23:50:25 +08:00
/** @return the name of the file where the exception was thrown
*/
2004-11-02 00:31:19 +08:00
final public function getFile()
{
return $this->file;
}
2004-11-01 23:50:25 +08:00
/** @return the line number where the exception was thrown
*/
2004-11-02 00:31:19 +08:00
final public function getLine()
{
return $this->line;
}
2004-11-01 23:50:25 +08:00
/** @return the stack trace as array
*/
2004-11-02 00:31:19 +08:00
final public function getTrace()
{
return $this->trace;
}
2004-11-01 23:50:25 +08:00
/** @return the stack trace as string
*/
2004-11-02 00:31:19 +08:00
final public function getTraceAsString()
{
}
2004-11-01 23:50:25 +08:00
/** @return string represenation of exception
*/
2004-11-02 00:31:19 +08:00
public function __toString()
{
return $this->string;
}
2004-11-01 23:50:25 +08:00
}
/** @ingroup SPL
* @brief Exception that represents error in the program logic.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* This kind of exceptions should directly leed to a fix in your code.
*/
class LogicException extends Exception
{
}
/** @ingroup SPL
* @brief Exception thrown when a function call was illegal.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
*/
class BadFunctionCallException extends LogicException
{
}
/** @ingroup SPL
* @brief Exception thrown when a method call was illegal.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
*/
class BadMethodCallException extends BadFunctionCallException
{
}
2004-11-01 23:50:25 +08:00
/** @ingroup SPL
* @brief Exception that denotes a value not in the valid domain was used.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* This kind of exception should be used to inform about domain erors in
* mathematical sense.
*
* @see RangeException
2004-11-01 23:50:25 +08:00
*/
class DomainException extends LogicException
{
}
/** @ingroup SPL
* @brief Exception that denotes invalid arguments were passed.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
*
* @see UnexpectedValueException
2004-11-01 23:50:25 +08:00
*/
class InvalidArgumentException extends LogicException
{
}
/** @ingroup SPL
* @brief Exception thrown when a parameter exceeds the allowed length.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* This can be used for strings length, array size, file size, number of
* elements read from an Iterator and so on.
*/
class LengthException extends LogicException
{
}
/** @ingroup SPL
* @brief Exception thrown when an illegal index was requested.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* This represents errors that should be detected at compile time.
*
* @see OutOfBoundsException
*/
class OutOfRangeException extends LogicException
{
}
/** @ingroup SPL
* @brief Exception thrown for errors that are only detectable at runtime.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*/
class RuntimeException extends Exception
{
}
/** @ingroup SPL
* @brief Exception thrown when an illegal index was requested.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* This represents errors that cannot be detected at compile time.
*
* @see OutOfRangeException
*/
2004-11-02 00:31:19 +08:00
class OutOfBoundsException extends RuntimeException
2004-11-01 23:50:25 +08:00
{
}
/** @ingroup SPL
* @brief Exception thrown to indicate arithmetic/buffer overflow.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*/
class OverflowException extends RuntimeException
{
}
/** @ingroup SPL
* @brief Exception thrown to indicate range errors during program execution.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*
* Normally this means there was an arithmetic error other than under/overflow.
* This is the runtime version of DomainException.
*
* @see DomainException
2004-11-01 23:50:25 +08:00
*/
class RangeException extends RuntimeException
{
}
/** @ingroup SPL
* @brief Exception thrown to indicate arithmetic/buffer underflow.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2004-11-01 23:50:25 +08:00
*/
class UnderflowException extends RuntimeException
{
}
/** @ingroup SPL
* @brief Exception thrown to indicate an unexpected value.
* @since PHP 5.1
*
* Typically this happens when a function calls another function and espects
* the return value to be of a certain type or value not including arithmetic
* or buffer related errors.
*
* @see InvalidArgumentException
*/
class UnexpectedValueException extends RuntimeException
{
}
2004-11-02 01:05:45 +08:00
/** @ingroup ZendEngine
* @brief Interface to override array access of objects.
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-05-07 06:55:25 +08:00
*/
interface ArrayAccess
{
2004-11-02 01:05:45 +08:00
/** @param $offset to modify
* @param $value new value
2004-05-07 06:55:25 +08:00
*/
function offsetSet($offset, $value);
2004-11-02 01:05:45 +08:00
/** @param $offset to retrieve
* @return value at given offset
2004-05-07 06:55:25 +08:00
*/
function offsetGet($offset);
2004-11-02 01:05:45 +08:00
/** @param $offset to delete
2004-05-07 06:55:25 +08:00
*/
function offsetUnset($offset);
2004-11-02 01:05:45 +08:00
/** @param $offset to check
* @return whether the offset exists.
2004-05-07 06:55:25 +08:00
*/
function offsetExists($offset);
}
2004-11-02 01:05:45 +08:00
/** @ingroup ZendEngine
* @brief Interface to detect a class is traversable using foreach.
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-05-08 20:26:28 +08:00
*
* Abstract base interface that cannot be implemented alone. Instead it
2003-12-05 03:39:46 +08:00
* must be implemented by either IteratorAggregate or Iterator.
2003-06-10 00:58:51 +08:00
*
2004-11-02 01:05:45 +08:00
* @note Internal classes that implement this interface can be used in a
2003-12-05 03:39:46 +08:00
* foreach construct and do not need to implement IteratorAggregate or
* Iterator.
2004-01-29 08:10:33 +08:00
*
2004-11-02 01:05:45 +08:00
* @note This is an engine internal interface which cannot be implemented
2004-05-07 05:20:50 +08:00
* in PHP scripts. Either IteratorAggregate or Iterator must be used
* instead.
2003-06-10 00:58:51 +08:00
*/
2004-01-29 08:10:33 +08:00
interface Traversable
{
2003-06-10 00:58:51 +08:00
}
2003-05-02 07:28:28 +08:00
2004-11-02 01:05:45 +08:00
/** @ingroup ZendEngine
* @brief Interface to create an external Iterator.
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-01-29 08:10:33 +08:00
*
2004-11-02 01:05:45 +08:00
* @note This is an engine internal interface.
2003-12-05 03:39:46 +08:00
*/
interface IteratorAggregate extends Traversable
2004-01-29 08:10:33 +08:00
{
2004-11-02 01:05:45 +08:00
/** @return an Iterator for the implementing object.
2003-06-10 00:58:51 +08:00
*/
2003-12-05 03:39:46 +08:00
function getIterator();
2003-06-10 00:58:51 +08:00
}
2003-05-02 07:28:28 +08:00
2004-11-02 01:05:45 +08:00
/** @ingroup ZendEngine
* @brief Basic iterator
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-05-08 20:26:28 +08:00
*
* Interface for external iterators or objects that can be iterated
2003-12-05 03:39:46 +08:00
* themselves internally.
2004-01-29 08:10:33 +08:00
*
2004-11-02 01:05:45 +08:00
* @note This is an engine internal interface.
2003-06-10 00:58:51 +08:00
*/
interface Iterator extends Traversable
2004-01-29 08:10:33 +08:00
{
2003-12-05 03:39:46 +08:00
/** Rewind the Iterator to the first element.
2003-06-10 00:58:51 +08:00
*/
function rewind();
2003-12-05 03:39:46 +08:00
/** Return the current element.
*/
function current();
/** Return the key of the current element.
2003-05-02 07:28:28 +08:00
*/
2003-06-10 00:58:51 +08:00
function key();
2003-05-02 07:28:28 +08:00
2003-12-05 03:39:46 +08:00
/** Move forward to next element.
*/
function next();
2003-05-02 07:28:28 +08:00
2003-12-05 03:39:46 +08:00
/** Check if there is a current element after calls to rewind() or next().
*/
function valid();
2003-06-10 00:58:51 +08:00
}
/** @ingroup SPL
* @brief This Interface allows to hook into the global count() function.
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
*/
interface Countable
{
/** @return the number the global function count() should show
*/
function count();
}
/** @ingroup ZendEngine
* @brief Interface for customized serializing
* @since 5.1
*
* Classes that implement this interface no longer support __sleep() and
* __wakeup(). The method serialized is called whenever an instance needs to
* be serialized. This does not invoke __destruct() or has any other side
* effect unless programmed inside the method. When the data is unserialized
* the class is known and the appropriate unserialize() method is called as a
* constructor instead of calling __construct(). If you need to execute the
* standard constructor you may do so in the method.
*/
interface Serializeable
{
/**
* @return string representation of the instance
*/
function serialize();
/**
* @note This is a constructor
*
* @param $serialized data read from stream to construct the instance
*/
function unserialize($serialized);
}
2004-11-02 01:05:45 +08:00
/** @ingroup SPL
* @brief An Array wrapper
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2005-09-03 03:11:10 +08:00
* @version 1.1
*
2004-04-27 05:34:45 +08:00
* This array wrapper allows to recursively iterate over Arrays and public
* Object properties.
*
2004-11-02 01:05:45 +08:00
* @see ArrayIterator
*/
class ArrayObject implements IteratorAggregate, ArrayAccess, Countable
2004-01-29 08:10:33 +08:00
{
/** Properties of the object have their normal functionality
* when accessed as list (var_dump, foreach, etc.) */
const STD_PROP_LIST = 0x00000001;
/** Array indices can be accessed as properties in read/write */
const ARRAY_AS_PROPS = 0x00000002;
2003-12-05 03:39:46 +08:00
/** Construct a new array iterator from anything that has a hash table.
* That is any Array or Object.
*
2004-11-02 01:05:45 +08:00
* @param $array the array to use.
2005-09-03 03:11:10 +08:00
* @param $flags see setFlags().
*/
2005-09-03 03:11:10 +08:00
function __construct($array, $flags = 0);
/** Set behavior flags.
*
* @param $flags bitmask as follows:
* 0 set: properties of the object have their normal functionality
* when accessed as list (var_dump, foreach, etc.)
* 1 set: array indices can be accessed as properties in read/write
*/
function setFlags($flags);
/**
* @ return current flags
*/
function getFlags();
/**
* @param $array new array or object
*/
function exchangeArray($array);
2004-11-02 01:05:45 +08:00
/** @return the iterator which is an ArrayIterator object connected to
2004-04-27 05:34:45 +08:00
* this object.
*/
2003-12-05 03:39:46 +08:00
function getIterator();
2004-04-27 05:34:45 +08:00
2004-11-02 01:05:45 +08:00
/** @param $index offset to inspect
* @return whetehr offset $index esists
2004-04-27 05:34:45 +08:00
*/
function offsetExists($index);
2004-11-02 01:05:45 +08:00
/** @param $index offset to return value for
* @return value at offset $index
2004-04-27 05:34:45 +08:00
*/
function offsetGet($index);
2004-11-02 01:05:45 +08:00
/** @param $index index to set
* @param $newval new value to store at offset $index
2004-04-27 05:34:45 +08:00
*/
function offsetSet($index, $newval);
2004-11-02 01:05:45 +08:00
/** @param $index offset to unset
2004-04-27 05:34:45 +08:00
*/
function offsetUnset($index);
2004-11-02 01:05:45 +08:00
/** @param $value is appended as last element
* @warning this method cannot be called when the ArrayObject refers to
* an object.
2004-04-27 05:34:45 +08:00
*/
function append($value);
2004-11-02 01:05:45 +08:00
/** @return a \b copy of the array
* @note when the ArrayObject refers to an object then this method
* returns an array of the public properties.
2004-04-27 05:34:45 +08:00
*/
function getArrayCopy();
2004-05-07 05:20:50 +08:00
2004-11-02 01:05:45 +08:00
/** @return the number of elements in the array or the number of public
2004-05-07 05:20:50 +08:00
* properties in the object.
*/
function count();
}
2004-11-02 01:05:45 +08:00
/** @ingroup SPL
* @brief An Array iterator
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2005-09-03 03:11:10 +08:00
* @version 1.1
*
* This iterator allows to unset and modify values and keys while iterating
* over Arrays and Objects.
*
2004-04-27 05:34:45 +08:00
* When you want to iterate over the same array multiple times you need to
* instanciate ArrayObject and let it create ArrayIterator instances that
* refer to it either by using foreach or by calling its getIterator()
* method manually.
*/
2004-11-02 01:05:45 +08:00
class ArrayIterator implements SeekableIterator, ArrayAccess, Countable
2004-01-29 08:10:33 +08:00
{
/** Properties of the object have their normal functionality
* when accessed as list (var_dump, foreach, etc.) */
const STD_PROP_LIST = 0x00000001;
/** Array indices can be accessed as properties in read/write */
const ARRAY_AS_PROPS = 0x00000002;
2003-12-05 03:39:46 +08:00
/** Construct a new array iterator from anything that has a hash table.
* That is any Array or Object.
*
2004-11-02 01:05:45 +08:00
* @param $array the array to use.
2005-09-03 03:11:10 +08:00
* @param $flags see setFlags().
*/
function __construct($array, $flags = 0);
/** Set behavior flags.
*
* @param $flags bitmask as follows:
* 0 set: properties of the object have their normal functionality
* when accessed as list (var_dump, foreach, etc.)
* 1 set: array indices can be accessed as properties in read/write
*/
function setFlags($flags);
/**
* @ return current flags
*/
2005-09-03 03:11:10 +08:00
function getFlags();
2004-04-27 05:34:45 +08:00
2004-11-02 01:05:45 +08:00
/** @param $index offset to inspect
* @return whetehr offset $index esists
2004-04-27 05:34:45 +08:00
*/
function offsetExists($index);
2004-11-02 01:05:45 +08:00
/** @param $index offset to return value for
* @return value at offset $index
2004-04-27 05:34:45 +08:00
*/
function offsetGet($index);
2004-11-02 01:05:45 +08:00
/** @param $index index to set
* @param $newval new value to store at offset $index
2004-04-27 05:34:45 +08:00
*/
function offsetSet($index, $newval);
2004-11-02 01:05:45 +08:00
/** @param $index offset to unset
2004-04-27 05:34:45 +08:00
*/
function offsetUnset($index);
2004-11-02 01:05:45 +08:00
/** @param $value is appended as last element
* @warning this method cannot be called when the ArrayIterator refers to
* an object.
2004-04-27 05:34:45 +08:00
*/
function append($value);
2004-11-02 01:05:45 +08:00
/** @return a \b copy of the array
* @note when the ArrayIterator refers to an object then this method
* returns an array of the public properties.
2004-04-27 05:34:45 +08:00
*/
function getArrayCopy();
2004-11-02 01:05:45 +08:00
/** @param $position offset to seek to
2005-03-02 07:44:05 +08:00
* @throw OutOfBoundsException if $position is invalid
2004-04-27 05:34:45 +08:00
*/
function seek($position);
2003-12-05 03:39:46 +08:00
2004-11-02 01:05:45 +08:00
/** @return the number of elements in the array or the number of public
2004-05-07 05:20:50 +08:00
* properties in the object.
*/
function count();
}
2004-11-02 01:05:45 +08:00
/** @ingroup SPL
* @brief Directory iterator
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
*/
2004-01-29 08:10:33 +08:00
class DirectoryIterator implements Iterator
{
2003-12-05 03:39:46 +08:00
/** Construct a directory iterator from a path-string.
*
2004-11-02 01:05:45 +08:00
* @param $path directory to iterate.
*/
function __construct($path);
2004-11-02 01:05:45 +08:00
/** @return The opened path.
2003-12-05 03:39:46 +08:00
*/
function getPath();
2004-11-02 01:05:45 +08:00
/** @return The current file name.
2003-12-05 03:39:46 +08:00
*/
function getFilename();
2004-11-02 01:05:45 +08:00
/** @return The current entries path and file name.
*/
2003-12-05 03:39:46 +08:00
function getPathname();
2004-11-02 01:05:45 +08:00
/** @return The current entry's permissions.
2004-04-27 05:34:45 +08:00
*/
function getPerms();
2004-11-02 01:05:45 +08:00
/** @return The current entry's inode.
2004-04-27 05:34:45 +08:00
*/
function getInode();
2004-11-02 01:05:45 +08:00
/** @return The current entry's size in bytes .
2004-04-27 05:34:45 +08:00
*/
function getSize();
2004-11-02 01:05:45 +08:00
/** @return The current entry's owner name.
2004-04-27 05:34:45 +08:00
*/
function getOwner();
2004-11-02 01:05:45 +08:00
/** @return The current entry's group name.
2004-04-27 05:34:45 +08:00
*/
function getGroup();
2004-11-02 01:05:45 +08:00
/** @return The current entry's last access time.
2004-04-27 05:34:45 +08:00
*/
function getATime();
2004-11-02 01:05:45 +08:00
/** @return The current entry's last modification time.
2004-04-27 05:34:45 +08:00
*/
function getMTime();
2004-11-02 01:05:45 +08:00
/** @return The current entry's last change time.
2004-04-27 05:34:45 +08:00
*/
function getCTime();
2004-11-02 01:05:45 +08:00
/** @return The current entry's size in bytes .
2004-04-27 05:34:45 +08:00
*/
function getType();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is writeable.
2004-04-27 05:34:45 +08:00
*/
function isWritable();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is readable.
2004-04-27 05:34:45 +08:00
*/
function isReadable();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is executable.
2004-04-27 05:34:45 +08:00
*/
function isExecutable();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is .
2004-04-27 05:34:45 +08:00
*/
function isFile();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is a directory.
2003-12-05 03:39:46 +08:00
*/
function isDir();
2004-11-02 01:05:45 +08:00
/** @return Whether the current entry is either '.' or '..'.
2003-12-05 03:39:46 +08:00
*/
function isDot();
2004-04-27 05:34:45 +08:00
2004-11-02 01:05:45 +08:00
/** @return whether the current entry is a link.
2004-04-27 05:34:45 +08:00
*/
function isLink();
2004-11-02 01:05:45 +08:00
/** @return getFilename()
2004-04-27 05:34:45 +08:00
*/
function __toString();
/** Open the current file as a SplFileObject instance
*
* @param mode open mode
* @param use_include_path whether to search include paths (don't use)
* @param context resource context to pased to open function
* @throw RuntimeException if file cannot be opened (e.g. insufficient
* access rights).
* @return The opened file as a SplFileObject instance
*
* @see SplFileObject
* @see file()
*/
function DirectoryIterator::openFile($mode = 'r', $use_include_path = false, $context = NULL);
}
2003-12-05 03:39:46 +08:00
2004-11-02 01:05:45 +08:00
/** @ingroup SPL
* @brief recursive directory iterator
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2003-12-05 03:39:46 +08:00
*/
2004-01-29 08:10:33 +08:00
class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator
{
2004-11-02 01:05:45 +08:00
/** @return whether the current is a directory (not '.' or '..').
2003-12-05 03:39:46 +08:00
*/
function hasChildren();
2004-11-02 01:05:45 +08:00
/** @return a RecursiveDirectoryIterator for the current entry.
2003-12-05 03:39:46 +08:00
*/
function getChildren();
2004-01-29 08:10:33 +08:00
}
2004-11-02 01:05:45 +08:00
/** @ingroup SPL
* @brief recursive SimpleXML_Element iterator
2005-02-17 08:24:57 +08:00
* @since PHP 5.0
2004-08-29 18:33:24 +08:00
*
2004-08-29 19:54:38 +08:00
* The SimpleXMLIterator implements the RecursiveIterator interface. This
* allows iteration over all elements using foreach or an appropriate while
* construct, just like SimpleXMLElement does. When using the foreach construct,
* you will also iterate over the subelements. For every element which
* has subelements, hasChildren() returns true. This will trigger a call to
* getChildren() which returns the iterator for that sub element.
2004-01-29 08:10:33 +08:00
*/
2004-04-27 05:34:45 +08:00
class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator
2004-01-29 08:10:33 +08:00
{
2004-11-02 01:05:45 +08:00
/** @return whether the current node has sub nodes.
2004-01-29 08:10:33 +08:00
*/
function hasChildren();
2004-11-02 01:05:45 +08:00
/** @return a SimpleXMLIterator for the current node.
2004-01-29 08:10:33 +08:00
*/
function getChildren();
2003-12-05 03:39:46 +08:00
}
2005-02-09 04:42:48 +08:00
/** @ingroup SPL
* @brief observer of the observer pattern
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2005-02-09 04:42:48 +08:00
*
* For a detailed explanation see Observer pattern in
* <em>
* Gamma, Helm, Johnson, Vlissides<br />
* Design Patterns
* </em>
*/
interface Observer
{
/** Called from the subject (i.e. when it's value has changed).
* @param $subject the callee
*/
function update(Subject $subject);
}
/** @ingroup SPL
* @brief ubject to the observer pattern
2005-02-17 08:24:57 +08:00
* @since PHP 5.1
2005-02-09 04:42:48 +08:00
* @see Observer
*/
interface Subject
{
/** @param $observer new observer to attach
*/
function attach(Observer $observer);
/** @param $observer existing observer to detach
* @note a non attached observer shouldn't result in a warning or similar
*/
function detach(Observer $observer);
2005-02-17 08:16:00 +08:00
/** Notify all observers
2005-02-09 04:42:48 +08:00
*/
2005-02-17 08:16:00 +08:00
function notify();
2005-02-09 04:42:48 +08:00
}
?>