2003-05-01 23:28:28 +00:00
|
|
|
<?php
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Standard PHP Library
|
2003-05-01 23:28:28 +00:00
|
|
|
*
|
2004-03-09 17:01:21 +00:00
|
|
|
* (c) Marcus Boerger, 2003 - 2004
|
2003-05-01 23:28:28 +00:00
|
|
|
*/
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Abstract base interface that cannot be implemented alone. Instead it
|
|
|
|
* must be implemented by either IteratorAggregate or Iterator.
|
2003-06-09 16:58:51 +00:00
|
|
|
*
|
2003-12-04 19:39:46 +00:00
|
|
|
* \note Internal classes that implement this interface can be used in a
|
|
|
|
* foreach construct and do not need to implement IteratorAggregate or
|
|
|
|
* Iterator.
|
2004-01-29 00:10:33 +00:00
|
|
|
*
|
|
|
|
* \note This is an engine internal interface.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
interface Traversable
|
|
|
|
{
|
2003-06-09 16:58:51 +00:00
|
|
|
}
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Interface to create an external Iterator.
|
2004-01-29 00:10:33 +00:00
|
|
|
*
|
|
|
|
* \note This is an engine internal interface.
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
interface IteratorAggregate implements Traversable
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Return an Iterator for the implementing object.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getIterator();
|
2003-06-09 16:58:51 +00:00
|
|
|
}
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Interface for external iterators or objects that can be iterated
|
|
|
|
* themselves internally.
|
2004-01-29 00:10:33 +00:00
|
|
|
*
|
|
|
|
* \note This is an engine internal interface.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
interface Iterator implements Traversable
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Rewind the Iterator to the first element.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
|
|
|
function rewind();
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Return the current element.
|
|
|
|
*/
|
|
|
|
function current();
|
|
|
|
|
|
|
|
/** Return the key of the current element.
|
2003-05-01 23:28:28 +00:00
|
|
|
*/
|
2003-06-09 16:58:51 +00:00
|
|
|
function key();
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Move forward to next element.
|
|
|
|
*/
|
|
|
|
function next();
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Check if there is a current element after calls to rewind() or next().
|
|
|
|
*/
|
2004-03-08 17:33:31 +00:00
|
|
|
function valid();
|
2003-06-09 16:58:51 +00:00
|
|
|
}
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Interface for recursive traversal to be used with
|
|
|
|
* RecursiveIteratorIterator.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
interface RecursiveIterator implements Iterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \return whether current element can be iterated itself.
|
|
|
|
*/
|
|
|
|
function hasChildren();
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \return an object that recursively iterates the current element.
|
|
|
|
* This object must implement RecursiveIterator.
|
2003-05-01 23:28:28 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getChildren();
|
2003-06-09 16:58:51 +00:00
|
|
|
}
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Class for recursive traversal. The objects of this class are created by
|
|
|
|
* instances of RecursiveIterator. Elements of those iterators may be
|
|
|
|
* traversable themselves. If so these sub elements are recursed into.
|
2003-06-09 16:58:51 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class RecursiveIteratorIterator implements Iterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct an instance form a RecursiveIterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner root iterator
|
|
|
|
* \param $mode one of
|
|
|
|
* - RIT_LEAVES_ONLY do not return elements that can be recursed.
|
|
|
|
* - RIT_SELF_FIRST show elements before their sub elements.
|
|
|
|
* - RIT_CHILD_FIRST show elements after their sub elements-
|
|
|
|
*
|
|
|
|
* \note If you want to see only those elements which have sub elements then
|
|
|
|
* use a ParentIterator.
|
|
|
|
*/
|
|
|
|
function __construct(RecursiveIterator $iterator, $mode);
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \return the level of recursion (>=0).
|
2003-05-01 23:28:28 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getDepth();
|
2003-08-04 23:00:57 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \param $level the level of the sub iterator to return.
|
|
|
|
* \return the current inner sub iterator or the iterator at the
|
|
|
|
* specified $level.
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getSubIterator([$level]);
|
2003-08-04 23:00:57 +00:00
|
|
|
}
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \brief An Array wrapper
|
2003-08-04 23:00:57 +00:00
|
|
|
*
|
|
|
|
* This array wrapper allows to recursively iterate over Arrays and Objects.
|
|
|
|
*
|
2003-12-04 19:39:46 +00:00
|
|
|
* \see ArrayIterator
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class ArrayObject implements IteratorAggregate
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct a new array iterator from anything that has a hash table.
|
2003-08-04 23:00:57 +00:00
|
|
|
* That is any Array or Object.
|
|
|
|
*
|
|
|
|
* \param $array the array to use.
|
|
|
|
*/
|
|
|
|
function __construct($array);
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Get the iterator which is a ArrayIterator object connected to this
|
|
|
|
* object.
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getIterator();
|
2003-08-04 23:00:57 +00:00
|
|
|
}
|
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \brief An Array iterator
|
2003-08-04 23:00:57 +00:00
|
|
|
*
|
|
|
|
* This iterator allows to unset and modify values and keys while iterating
|
|
|
|
* over Arrays and Objects.
|
|
|
|
*
|
2003-12-04 19:39:46 +00:00
|
|
|
* To use this class you must instanciate ArrayObject.
|
2004-01-29 00:10:33 +00:00
|
|
|
* You cannot instanciate an ArrayIterator directly.
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class ArrayIterator implements Iterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct a new array iterator from anything that has a hash table.
|
2003-08-04 23:00:57 +00:00
|
|
|
* That is any Array or Object.
|
|
|
|
*
|
|
|
|
* \param $array the array to use.
|
|
|
|
*/
|
2003-08-04 23:15:56 +00:00
|
|
|
private function __construct($array);
|
2003-12-04 19:39:46 +00:00
|
|
|
}
|
|
|
|
|
2003-12-04 20:01:46 +00:00
|
|
|
/** Iterator that wrapps around another iterator and only returns selected
|
|
|
|
* elements of the inner iterator.
|
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
abstract class FilterIterator implements Iterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct an instance form a Iterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner iterator
|
|
|
|
*/
|
|
|
|
function __construct(Iterator $iterator);
|
|
|
|
|
|
|
|
/** \return whether the current element of the inner iterator should be
|
|
|
|
* used as a current element of this iterator or if it should be skipped.
|
|
|
|
*/
|
|
|
|
abstract function accept();
|
2004-03-09 17:36:32 +00:00
|
|
|
|
|
|
|
/** \return the inner Iterator
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function getInnerIterator();
|
|
|
|
}
|
2003-08-04 23:00:57 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
interface SeekableIterator implements Iterator
|
|
|
|
{
|
|
|
|
/** Seek to a specific position if available or throw an exception.
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function seek($position);
|
|
|
|
}
|
2003-08-04 23:00:57 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** A class that starts iteration at a certain offset and only iterates over
|
|
|
|
* a specified amount of elements.
|
|
|
|
*/
|
|
|
|
class LimitIetrator implements Iterator
|
|
|
|
{
|
|
|
|
/** Construct an instance form a Iterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner iterator
|
|
|
|
* \param $offset starting position (zero based)
|
|
|
|
* \param $count amount of elements returned, if available)
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function __construct(Iterator $iterator, $offset = 0, $count = -1);
|
2003-08-04 23:00:57 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** \return whether the current element of the inner iterator should be
|
|
|
|
* used as a current element of this iterator or if it should be skipped.
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
abstract function accept();
|
|
|
|
|
|
|
|
/** \return the inner Iterator
|
2003-08-04 23:00:57 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function getInnerIterator();
|
|
|
|
|
|
|
|
/** Seek to a specific position if available or throw an exception.
|
|
|
|
* If the inner iterator is an instance of SeekableIterator its seek()
|
|
|
|
* method will be used. Otherwise the iterator will me manually forwared
|
|
|
|
* and rewinded first if necessary.
|
|
|
|
*/
|
|
|
|
function seek($position);
|
|
|
|
|
|
|
|
/** return the current position (zero based)
|
|
|
|
*/
|
|
|
|
function getPosition();
|
2003-06-09 16:58:51 +00:00
|
|
|
}
|
2003-05-01 23:28:28 +00:00
|
|
|
|
2003-12-04 20:01:46 +00:00
|
|
|
/** A recursive iterator that only returns elements that themselves can be
|
|
|
|
* trversed.
|
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class ParentIterator extends FilterIterator implements RecursiveIterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct an instance form a RecursiveIterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner iterator
|
|
|
|
*/
|
|
|
|
function __construct(RecursiveIterator $iterator);
|
2004-03-09 17:36:32 +00:00
|
|
|
}
|
2003-12-04 19:39:46 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** This Iterator allways reads one ahead. That allows it to know whether
|
|
|
|
* more elements are available.
|
|
|
|
*/
|
|
|
|
class CachingIterator implements Iterator
|
|
|
|
{
|
|
|
|
/** Construct an instance form a RecursiveIterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner iterator
|
|
|
|
* \param $getStrVal whether to fetch the value returned by __toString()
|
|
|
|
* or the (string) conversion. This is optional since
|
|
|
|
* it is not always used nad takes an additional fcall.
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function __construct(Iterator $iterator, $getStrVal = false);
|
2003-12-04 19:39:46 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** \return whether the inner iterator is valid. That is this iterator
|
|
|
|
* is valid and has one more element.
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function hasNext();
|
2003-12-04 19:39:46 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** \return The last value from the inner iterators __toString() or
|
|
|
|
* (string) conversion. The value is only fetched when the __constructor
|
|
|
|
* was called with $getStrVal = true.
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function __tostring();
|
|
|
|
|
|
|
|
/** \return the inner Iterator
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function getInnerIterator();
|
|
|
|
}
|
2003-12-04 19:39:46 +00:00
|
|
|
|
2004-03-09 17:36:32 +00:00
|
|
|
/** The recursive version of the CachingIterator.
|
|
|
|
*/
|
|
|
|
class CachingRecursiveIterator extends CachingIterator implemnets RecursiveIterator
|
|
|
|
{
|
|
|
|
/** Construct an instance form a RecursiveIterator.
|
|
|
|
*
|
|
|
|
* \param $iterator inner iterator
|
|
|
|
* \param $getStrVal whether to fetch the value returned by __toString()
|
|
|
|
* or the (string) conversion. This is optional since
|
|
|
|
* it is not always used nad takes an additional fcall.
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-03-09 17:36:32 +00:00
|
|
|
function __construct(RecursiveIterator $iterator, $getStrVal);
|
2003-12-04 19:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Directory iterator
|
2003-08-04 23:15:56 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class DirectoryIterator implements Iterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** Construct a directory iterator from a path-string.
|
2003-08-04 23:15:56 +00:00
|
|
|
*
|
|
|
|
* \param $path directory to iterate.
|
|
|
|
*/
|
2003-08-04 23:21:27 +00:00
|
|
|
function __construct($path);
|
2003-08-04 23:15:56 +00:00
|
|
|
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \return The opened path.
|
|
|
|
*/
|
|
|
|
function getPath();
|
|
|
|
|
|
|
|
/** \return The current file name.
|
|
|
|
*/
|
|
|
|
function getFilename();
|
|
|
|
|
|
|
|
/** \return The current entries path and file name.
|
2003-08-04 23:15:56 +00:00
|
|
|
*/
|
2003-12-04 19:39:46 +00:00
|
|
|
function getPathname();
|
|
|
|
|
|
|
|
/** \return Whether the current entry is a directory.
|
|
|
|
*/
|
|
|
|
function isDir();
|
|
|
|
|
|
|
|
/** \return Whether the current entry is either '.' or '..'.
|
|
|
|
*/
|
|
|
|
function isDot();
|
2003-08-04 23:15:56 +00:00
|
|
|
}
|
2003-12-04 19:39:46 +00:00
|
|
|
|
2003-12-04 20:01:46 +00:00
|
|
|
/** \brief recursive directory iterator
|
2003-12-04 19:39:46 +00:00
|
|
|
*/
|
2004-01-29 00:10:33 +00:00
|
|
|
class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator
|
|
|
|
{
|
2003-12-04 19:39:46 +00:00
|
|
|
/** \return whether the current is a directory (not '.' or '..').
|
|
|
|
*/
|
|
|
|
function hasChildren();
|
|
|
|
|
|
|
|
/** \return a RecursiveDirectoryIterator for the current entry.
|
|
|
|
*/
|
|
|
|
function getChildren();
|
2004-01-29 00:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief recursive SimpleXML_Element iterator
|
|
|
|
*/
|
|
|
|
class SimpleXMLIterator extends simplexml_element implements RecursiveIterator
|
|
|
|
{
|
|
|
|
/** \return whether the current node has sub nodes.
|
|
|
|
*/
|
|
|
|
function hasChildren();
|
|
|
|
|
|
|
|
/** \return a SimpleXMLIterator for the current node.
|
|
|
|
*/
|
|
|
|
function getChildren();
|
2003-12-04 19:39:46 +00:00
|
|
|
}
|
|
|
|
|
2003-05-01 23:28:28 +00:00
|
|
|
?>
|