helly Wed Apr 28 15:58:48 2004 EDT Added files: /php-src/ext/spl/tests iterator_001.phpt iterator_002.phpt iterator_003.phpt iterator_004.phpt
Removed files: /php-src/ext/spl/tests caching_iterator_str.phpt iterator_aggregation.phpt iterator_get_inner.phpt limititerator.phpt Modified files: /php-src/ext/spl spl.php /php-src/ext/spl/examples appenditerator.inc findfile.inc findfile.php /php-src/ext/spl/tests array_005.phpt array_009.phpt array_011.phpt Log: - DOS 2 UNIX
http://cvs.php.net/diff.php/php-src/ext/spl/spl.php?r1=1.18&r2=1.19&ty=u Index: php-src/ext/spl/spl.php diff -u php-src/ext/spl/spl.php:1.18 php-src/ext/spl/spl.php:1.19 --- php-src/ext/spl/spl.php:1.18 Tue Apr 27 11:39:33 2004 +++ php-src/ext/spl/spl.php Wed Apr 28 15:58:47 2004 @@ -1,447 +1,447 @@ -<?php - -/** Standard PHP Library - * - * (c) Marcus Boerger, 2003 - 2004 - */ - -/** Abstract base interface that cannot be implemented alone. Instead it - * must be implemented by either IteratorAggregate or Iterator. - * - * \note Internal classes that implement this interface can be used in a - * foreach construct and do not need to implement IteratorAggregate or - * Iterator. - * - * \note This is an engine internal interface. - */ -interface Traversable -{ -} - -/** Interface to create an external Iterator. - * - * \note This is an engine internal interface. - */ -interface IteratorAggregate implements Traversable -{ - /** Return an Iterator for the implementing object. - */ - function getIterator(); -} - -/** Interface for external iterators or objects that can be iterated - * themselves internally. - * - * \note This is an engine internal interface. - */ -interface Iterator implements Traversable -{ - /** Rewind the Iterator to the first element. - */ +<?php + +/** Standard PHP Library + * + * (c) Marcus Boerger, 2003 - 2004 + */ + +/** Abstract base interface that cannot be implemented alone. Instead it + * must be implemented by either IteratorAggregate or Iterator. + * + * \note Internal classes that implement this interface can be used in a + * foreach construct and do not need to implement IteratorAggregate or + * Iterator. + * + * \note This is an engine internal interface. + */ +interface Traversable +{ +} + +/** Interface to create an external Iterator. + * + * \note This is an engine internal interface. + */ +interface IteratorAggregate implements Traversable +{ + /** Return an Iterator for the implementing object. + */ + function getIterator(); +} + +/** Interface for external iterators or objects that can be iterated + * themselves internally. + * + * \note This is an engine internal interface. + */ +interface Iterator implements Traversable +{ + /** Rewind the Iterator to the first element. + */ function rewind(); - - /** Return the current element. - */ + + /** Return the current element. + */ function current(); - - /** Return the key of the current element. - */ + + /** Return the key of the current element. + */ function key(); - - /** Move forward to next element. - */ + + /** Move forward to next element. + */ function next(); - - /** Check if there is a current element after calls to rewind() or next(). - */ + + /** Check if there is a current element after calls to rewind() or next(). + */ function valid(); -} - -/** Interface for recursive traversal to be used with - * RecursiveIteratorIterator. - */ -interface RecursiveIterator implements Iterator -{ - /** \return whether current element can be iterated itself. - */ - function hasChildren(); - - /** \return an object that recursively iterates the current element. - * This object must implement RecursiveIterator. - */ - function getChildren(); -} - -/** 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. - */ -class RecursiveIteratorIterator implements Iterator -{ - /** 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); - - /** \return the level of recursion (>=0). - */ - function getDepth(); - - /** \param $level the level of the sub iterator to return. - * \return the current inner sub iterator or the iterator at the - * specified $level. - */ - function getSubIterator([$level]); -} - -/** \brief An Array wrapper - * - * This array wrapper allows to recursively iterate over Arrays and public - * Object properties. - * - * \see ArrayIterator - */ -class ArrayObject implements IteratorAggregate, ArrayAccess -{ - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ - function __construct($array); - - /** \return the iterator which is an ArrayIterator object connected to - * this object. - */ - function getIterator(); - - /** \param $index offset to inspect - * \return whetehr offset $index esists - */ - function offsetExists($index); - - /** \param $index offset to return value for - * \return value at offset $index - */ - function offsetGet($index); - - /** \param $index index to set - * \param $newval new value to store at offset $index - */ - function offsetSet($index, $newval); - - /** \param $index offset to unset - */ - function offsetUnset($index); - - /** \param $value is appended as last element - */ - function append($value); - - /** \return a \b copy of the array - */ - function getArrayCopy(); -} - -/** \brief An Array iterator - * - * This iterator allows to unset and modify values and keys while iterating - * over Arrays and Objects. - * - * 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. - */ -class ArrayIterator implements Iterator, SeekableIterator, ArrayAccess -{ - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ +} + +/** Interface for recursive traversal to be used with + * RecursiveIteratorIterator. + */ +interface RecursiveIterator implements Iterator +{ + /** \return whether current element can be iterated itself. + */ + function hasChildren(); + + /** \return an object that recursively iterates the current element. + * This object must implement RecursiveIterator. + */ + function getChildren(); +} + +/** 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. + */ +class RecursiveIteratorIterator implements Iterator +{ + /** 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); + + /** \return the level of recursion (>=0). + */ + function getDepth(); + + /** \param $level the level of the sub iterator to return. + * \return the current inner sub iterator or the iterator at the + * specified $level. + */ + function getSubIterator([$level]); +} + +/** \brief An Array wrapper + * + * This array wrapper allows to recursively iterate over Arrays and public + * Object properties. + * + * \see ArrayIterator + */ +class ArrayObject implements IteratorAggregate, ArrayAccess +{ + /** Construct a new array iterator from anything that has a hash table. + * That is any Array or Object. + * + * \param $array the array to use. + */ + function __construct($array); + + /** \return the iterator which is an ArrayIterator object connected to + * this object. + */ + function getIterator(); + + /** \param $index offset to inspect + * \return whetehr offset $index esists + */ + function offsetExists($index); + + /** \param $index offset to return value for + * \return value at offset $index + */ + function offsetGet($index); + + /** \param $index index to set + * \param $newval new value to store at offset $index + */ + function offsetSet($index, $newval); + + /** \param $index offset to unset + */ + function offsetUnset($index); + + /** \param $value is appended as last element + */ + function append($value); + + /** \return a \b copy of the array + */ + function getArrayCopy(); +} + +/** \brief An Array iterator + * + * This iterator allows to unset and modify values and keys while iterating + * over Arrays and Objects. + * + * 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. + */ +class ArrayIterator implements Iterator, SeekableIterator, ArrayAccess +{ + /** Construct a new array iterator from anything that has a hash table. + * That is any Array or Object. + * + * \param $array the array to use. + */ public function __construct($array); - - /** \param $index offset to inspect - * \return whetehr offset $index esists - */ - function offsetExists($index); - - /** \param $index offset to return value for - * \return value at offset $index - */ - function offsetGet($index); - - /** \param $index index to set - * \param $newval new value to store at offset $index - */ - function offsetSet($index, $newval); - - /** \param $index offset to unset - */ - function offsetUnset($index); - - /** \param $value is appended as last element - */ - function append($value); - - /** \return a \b copy of the array - */ - function getArrayCopy(); - - /** \param $position offset to seek to - */ - function seek($position); - -/** Iterator that wrapps around another iterator and only returns selected - * elements of the inner iterator. - */ -abstract class FilterIterator implements Iterator -{ - /** 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(); - - /** \return the inner Iterator - */ + + /** \param $index offset to inspect + * \return whetehr offset $index esists + */ + function offsetExists($index); + + /** \param $index offset to return value for + * \return value at offset $index + */ + function offsetGet($index); + + /** \param $index index to set + * \param $newval new value to store at offset $index + */ + function offsetSet($index, $newval); + + /** \param $index offset to unset + */ + function offsetUnset($index); + + /** \param $value is appended as last element + */ + function append($value); + + /** \return a \b copy of the array + */ + function getArrayCopy(); + + /** \param $position offset to seek to + */ + function seek($position); + +/** Iterator that wrapps around another iterator and only returns selected + * elements of the inner iterator. + */ +abstract class FilterIterator implements Iterator +{ + /** 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(); + + /** \return the inner Iterator + */ function getInnerIterator(); -} - -/** This interface is used to optimize LimitIterator functionality. but it - * may also be used for other situations where seeking a specific offset is - * required and easily possible. - */ -interface SeekableIterator implements Iterator -{ - /** Seek to a specific position if available or throw an exception. - * \param $position offset to seek to. - */ - function seek($position); -} - -/** A class that starts iteration at a certain offset and only iterates over - * a specified amount of elements. - * - * This class uses SeekableIterator::seek() if available and rewind() plus - * a skip loop otehrwise. - */ -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) - */ - function __construct(Iterator $iterator, $offset = 0, $count = -1); - - /** \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(); - - /** \return the inner Iterator - */ - 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) - */ +} + +/** This interface is used to optimize LimitIterator functionality. but it + * may also be used for other situations where seeking a specific offset is + * required and easily possible. + */ +interface SeekableIterator implements Iterator +{ + /** Seek to a specific position if available or throw an exception. + * \param $position offset to seek to. + */ + function seek($position); +} + +/** A class that starts iteration at a certain offset and only iterates over + * a specified amount of elements. + * + * This class uses SeekableIterator::seek() if available and rewind() plus + * a skip loop otehrwise. + */ +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) + */ + function __construct(Iterator $iterator, $offset = 0, $count = -1); + + /** \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(); + + /** \return the inner Iterator + */ + 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(); -} - -/** A recursive iterator that only returns elements that themselves can be - * trversed. - */ -class ParentIterator extends FilterIterator implements RecursiveIterator -{ - /** Construct an instance form a RecursiveIterator. - * - * \param $iterator inner iterator - */ - function __construct(RecursiveIterator $iterator); -} - -/** 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. - */ - function __construct(Iterator $iterator, $getStrVal = false); - - /** \return whether the inner iterator is valid. That is this iterator - * is valid and has one more element. - */ - function valid(); - - /** \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. - */ +} + +/** A recursive iterator that only returns elements that themselves can be + * trversed. + */ +class ParentIterator extends FilterIterator implements RecursiveIterator +{ + /** Construct an instance form a RecursiveIterator. + * + * \param $iterator inner iterator + */ + function __construct(RecursiveIterator $iterator); +} + +/** 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. + */ + function __construct(Iterator $iterator, $getStrVal = false); + + /** \return whether the inner iterator is valid. That is this iterator + * is valid and has one more element. + */ + function valid(); + + /** \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. + */ function __tostring(); - - /** \return the inner Iterator - */ - function getInnerIterator(); -} - -/** 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. - */ - function __construct(RecursiveIterator $iterator, $getStrVal); -} - -/** \brief Directory iterator - */ -class DirectoryIterator implements Iterator -{ - /** Construct a directory iterator from a path-string. - * - * \param $path directory to iterate. - */ + + /** \return the inner Iterator + */ + function getInnerIterator(); +} + +/** 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. + */ + function __construct(RecursiveIterator $iterator, $getStrVal); +} + +/** \brief Directory iterator + */ +class DirectoryIterator implements Iterator +{ + /** Construct a directory iterator from a path-string. + * + * \param $path directory to iterate. + */ function __construct($path); - - /** \return The opened path. - */ + + /** \return The opened path. + */ function getPath(); - - /** \return The current file name. - */ + + /** \return The current file name. + */ function getFilename(); - - /** \return The current entries path and file name. - */ + + /** \return The current entries path and file name. + */ function getPathname(); - - /** \return The current entry's permissions. - */ - function getPerms(); - - /** \return The current entry's inode. - */ - function getInode(); - - /** \return The current entry's size in bytes . - */ - function getSize(); - - /** \return The current entry's owner name. - */ - function getOwner(); - - /** \return The current entry's group name. - */ - function getGroup(); - - /** \return The current entry's last access time. - */ - function getATime(); - - /** \return The current entry's last modification time. - */ - function getMTime(); - - /** \return The current entry's last change time. - */ - function getCTime(); - - /** \return The current entry's size in bytes . - */ - function getType(); - - /** \return Whether the current entry is writeable. - */ - function isWritable(); - - /** \return Whether the current entry is readable. - */ - function isReadable(); - - /** \return Whether the current entry is executable. - */ - function isExecutable(); - - /** \return Whether the current entry is . - */ - function isFile(); - - /** \return Whether the current entry is a directory. - */ + + /** \return The current entry's permissions. + */ + function getPerms(); + + /** \return The current entry's inode. + */ + function getInode(); + + /** \return The current entry's size in bytes . + */ + function getSize(); + + /** \return The current entry's owner name. + */ + function getOwner(); + + /** \return The current entry's group name. + */ + function getGroup(); + + /** \return The current entry's last access time. + */ + function getATime(); + + /** \return The current entry's last modification time. + */ + function getMTime(); + + /** \return The current entry's last change time. + */ + function getCTime(); + + /** \return The current entry's size in bytes . + */ + function getType(); + + /** \return Whether the current entry is writeable. + */ + function isWritable(); + + /** \return Whether the current entry is readable. + */ + function isReadable(); + + /** \return Whether the current entry is executable. + */ + function isExecutable(); + + /** \return Whether the current entry is . + */ + function isFile(); + + /** \return Whether the current entry is a directory. + */ function isDir(); - - /** \return Whether the current entry is either '.' or '..'. - */ + + /** \return Whether the current entry is either '.' or '..'. + */ function isDot(); - - /** \return whether the current entry is a link. - */ - function isLink(); - - /** \return getFilename() - */ - function __toString(); -} - -/** \brief recursive directory iterator - */ -class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator -{ - /** \return whether the current is a directory (not '.' or '..'). - */ + + /** \return whether the current entry is a link. + */ + function isLink(); + + /** \return getFilename() + */ + function __toString(); +} + +/** \brief recursive directory iterator + */ +class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator +{ + /** \return whether the current is a directory (not '.' or '..'). + */ function hasChildren(); - - /** \return a RecursiveDirectoryIterator for the current entry. - */ - function getChildren(); -} - -/** \brief recursive SimpleXML_Element iterator - */ -class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator -{ - /** \return whether the current node has sub nodes. - */ + + /** \return a RecursiveDirectoryIterator for the current entry. + */ + function getChildren(); +} + +/** \brief recursive SimpleXML_Element iterator + */ +class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator +{ + /** \return whether the current node has sub nodes. + */ function hasChildren(); - - /** \return a SimpleXMLIterator for the current node. - */ + + /** \return a SimpleXMLIterator for the current node. + */ function getChildren(); -} - +} + ?> \ No newline at end of file http://cvs.php.net/diff.php/php-src/ext/spl/examples/appenditerator.inc?r1=1.2&r2=1.3&ty=u Index: php-src/ext/spl/examples/appenditerator.inc diff -u php-src/ext/spl/examples/appenditerator.inc:1.2 php-src/ext/spl/examples/appenditerator.inc:1.3 --- php-src/ext/spl/examples/appenditerator.inc:1.2 Mon Apr 26 18:01:12 2004 +++ php-src/ext/spl/examples/appenditerator.inc Wed Apr 28 15:58:47 2004 @@ -1,80 +1,80 @@ -<?php - -/** - * @brief Iterator that iterates over several iterators one after the other - * @author Marcus Boerger - * @version 1.0 - * - */ -class AppendIterator implements Iterator -{ - protected $iterators; - - function __construct() - { - $this->iterators = new ArrayIterator(); - } - - function append(Iterator $it) - { - $this->iterators->append($it); - } - - function getInnerIterator() - { - return $this->iterators->current(); - } - - function rewind() - { - $this->iterators->rewind(); - if ($this->iterators->valid()) - { - $this->iterators->rewind(); - } - } - - function valid() - { - return $this->iterators->valid() && $this->getInnerIterator()->valid(); - } - - function current() - { - /* Using $this->valid() would be exactly the same; it would omit - * the access to a non valid element in the inner iterator. Since - * the user didn't respect the valid() return value false this - * must be intended hence we go on. */ - return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL; - } - - function key() - { - return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL; - } - - function next() - { - if (!$this->iterators->valid()) - { - return; /* done all */ - } - $this->getInnerIterator()->next(); - if ($this->getInnerIterator()->valid()) - { - return; /* found valid element in current inner iterator */ - } - $this->iterators->next(); - while ($this->iterators->valid()) - { - $this->getInnerIterator()->rewind(); - if ($this->getInnerIterator()->valid()) - { - return; /* found element as first elemet in another iterator */ - } - $this->iterators->next(); - } - } -} - +<?php + +/** + * @brief Iterator that iterates over several iterators one after the other + * @author Marcus Boerger + * @version 1.0 + * + */ +class AppendIterator implements Iterator +{ + protected $iterators; + + function __construct() + { + $this->iterators = new ArrayIterator(); + } + + function append(Iterator $it) + { + $this->iterators->append($it); + } + + function getInnerIterator() + { + return $this->iterators->current(); + } + + function rewind() + { + $this->iterators->rewind(); + if ($this->iterators->valid()) + { + $this->iterators->rewind(); + } + } + + function valid() + { + return $this->iterators->valid() && $this->getInnerIterator()->valid(); + } + + function current() + { + /* Using $this->valid() would be exactly the same; it would omit + * the access to a non valid element in the inner iterator. Since + * the user didn't respect the valid() return value false this + * must be intended hence we go on. */ + return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL; + } + + function key() + { + return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL; + } + + function next() + { + if (!$this->iterators->valid()) + { + return; /* done all */ + } + $this->getInnerIterator()->next(); + if ($this->getInnerIterator()->valid()) + { + return; /* found valid element in current inner iterator */ + } + $this->iterators->next(); + while ($this->iterators->valid()) + { + $this->getInnerIterator()->rewind(); + if ($this->getInnerIterator()->valid()) + { + return; /* found element as first elemet in another iterator */ + } + $this->iterators->next(); + } + } +} + ?> \ No newline at end of file http://cvs.php.net/diff.php/php-src/ext/spl/examples/findfile.inc?r1=1.2&r2=1.3&ty=u Index: php-src/ext/spl/examples/findfile.inc diff -u php-src/ext/spl/examples/findfile.inc:1.2 php-src/ext/spl/examples/findfile.inc:1.3 --- php-src/ext/spl/examples/findfile.inc:1.2 Sun Apr 25 09:06:15 2004 +++ php-src/ext/spl/examples/findfile.inc Wed Apr 28 15:58:47 2004 @@ -1,34 +1,34 @@ -<?php - -/** - * @brief Base class to find files - * @author Marcus Boerger - * @version 1.0 - * - */ -class FindFile extends FilterIterator -{ - protected $file; - - function __construct($path, $file) - { - $this->file = $file; - $list = split(';', $path); - if (count($list) <= 1) { - parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } else { - $it = new AppendIterator(); - foreach($list as $path) { - $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } - parent::__construct($it); - } - } - - function accept() - { - return !strcmp($this->current(), $this->file); - } -} - +<?php + +/** + * @brief Base class to find files + * @author Marcus Boerger + * @version 1.0 + * + */ +class FindFile extends FilterIterator +{ + protected $file; + + function __construct($path, $file) + { + $this->file = $file; + $list = split(';', $path); + if (count($list) <= 1) { + parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } else { + $it = new AppendIterator(); + foreach($list as $path) { + $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } + parent::__construct($it); + } + } + + function accept() + { + return !strcmp($this->current(), $this->file); + } +} + ?> \ No newline at end of file http://cvs.php.net/diff.php/php-src/ext/spl/examples/findfile.php?r1=1.6&r2=1.7&ty=u Index: php-src/ext/spl/examples/findfile.php diff -u php-src/ext/spl/examples/findfile.php:1.6 php-src/ext/spl/examples/findfile.php:1.7 --- php-src/ext/spl/examples/findfile.php:1.6 Sun Apr 25 09:06:15 2004 +++ php-src/ext/spl/examples/findfile.php Wed Apr 28 15:58:47 2004 @@ -1,29 +1,29 @@ -<?php - -/** Find a specific file by name. - * - * Usage: php findfile.php <path> <name> - * - * <path> Path to search in. You can specify multiple paths by separating - * them with ';'. - * <name> Filename to look for. - * - * (c) Marcus Boerger, 2003 - 2004 - */ - -if ($argc < 3) { - echo <<<EOF -Usage: php findfile.php <path> <name> - -Find a specific file by name. - -<path> Path to search in. -<name> Filename to look for. - - -EOF; - exit(1); -} - -foreach(new FindFile($argv[1], $argv[2]) as $file) echo $file->getPathname()."\n"; +<?php + +/** Find a specific file by name. + * + * Usage: php findfile.php <path> <name> + * + * <path> Path to search in. You can specify multiple paths by separating + * them with ';'. + * <name> Filename to look for. + * + * (c) Marcus Boerger, 2003 - 2004 + */ + +if ($argc < 3) { + echo <<<EOF +Usage: php findfile.php <path> <name> + +Find a specific file by name. + +<path> Path to search in. +<name> Filename to look for. + + +EOF; + exit(1); +} + +foreach(new FindFile($argv[1], $argv[2]) as $file) echo $file->getPathname()."\n"; ?> \ No newline at end of file http://cvs.php.net/diff.php/php-src/ext/spl/tests/array_005.phpt?r1=1.1&r2=1.2&ty=u Index: php-src/ext/spl/tests/array_005.phpt diff -u php-src/ext/spl/tests/array_005.phpt:1.1 php-src/ext/spl/tests/array_005.phpt:1.2 --- php-src/ext/spl/tests/array_005.phpt:1.1 Tue Apr 13 15:06:39 2004 +++ php-src/ext/spl/tests/array_005.phpt Wed Apr 28 15:58:47 2004 @@ -1,93 +1,93 @@ ---TEST-- -SPL: ArrayObject/Iterator interaction ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Student -{ - private $id; - private $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; - } - - public function __toString() - { - return $this->id . ', ' . $this->name; - } - - public function getId() - { - return $this->id; - } -} - -class StudentIdFilter extends FilterIterator -{ - private $id; - - public function __construct(ArrayObject $students, Student $other) - { - FilterIterator::__construct($students->getIterator()); - $this->id = $other->getId(); - } - - public function accept() - { - echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n"; - return $this->current()->getId() == $this->id; - } -} - -class StudentList implements IteratorAggregate -{ - private $students; - - public function __construct() - { - $this->students = new ArrayObject(array()); - } - - public function add(Student $student) - { - if (!$this->contains($student)) { - $this->students[] = $student; - } - } - - public function contains(Student $student) - { - foreach ($this->students as $s) - { - if ($s->getId() == $student->getId()) { - return true; - } - } - return false; - } - - public function getIterator() { - return $this->students->getIterator(); - } -} - -$students = new StudentList(); -$students->add(new Student('01234123', 'Joe')); -$students->add(new Student('00000014', 'Bob')); -$students->add(new Student('00000014', 'Foo')); - -foreach ($students as $student) { - echo $student, "\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -01234123, Joe -00000014, Bob -===DONE=== +--TEST-- +SPL: ArrayObject/Iterator interaction +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class Student +{ + private $id; + private $name; + + public function __construct($id, $name) + { + $this->id = $id; + $this->name = $name; + } + + public function __toString() + { + return $this->id . ', ' . $this->name; + } + + public function getId() + { + return $this->id; + } +} + +class StudentIdFilter extends FilterIterator +{ + private $id; + + public function __construct(ArrayObject $students, Student $other) + { + FilterIterator::__construct($students->getIterator()); + $this->id = $other->getId(); + } + + public function accept() + { + echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n"; + return $this->current()->getId() == $this->id; + } +} + +class StudentList implements IteratorAggregate +{ + private $students; + + public function __construct() + { + $this->students = new ArrayObject(array()); + } + + public function add(Student $student) + { + if (!$this->contains($student)) { + $this->students[] = $student; + } + } + + public function contains(Student $student) + { + foreach ($this->students as $s) + { + if ($s->getId() == $student->getId()) { + return true; + } + } + return false; + } + + public function getIterator() { + return $this->students->getIterator(); + } +} + +$students = new StudentList(); +$students->add(new Student('01234123', 'Joe')); +$students->add(new Student('00000014', 'Bob')); +$students->add(new Student('00000014', 'Foo')); + +foreach ($students as $student) { + echo $student, "\n"; +} +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +01234123, Joe +00000014, Bob +===DONE=== http://cvs.php.net/diff.php/php-src/ext/spl/tests/array_009.phpt?r1=1.1&r2=1.2&ty=u Index: php-src/ext/spl/tests/array_009.phpt diff -u php-src/ext/spl/tests/array_009.phpt:1.1 php-src/ext/spl/tests/array_009.phpt:1.2 --- php-src/ext/spl/tests/array_009.phpt:1.1 Sun Apr 25 07:14:11 2004 +++ php-src/ext/spl/tests/array_009.phpt Wed Apr 28 15:58:47 2004 @@ -1,37 +1,37 @@ ---TEST-- -SPL: ArrayIterator implementing RecursiveIterator ---FILE-- -<?php - -class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new RecursiceArrayIterator($this->current()); - } -} - -$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); - -$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RIT_LEAVES_ONLY); - -foreach ($dir as $file) { - print "$file\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1 -21 -221 -222 -231 -3 -===DONE=== +--TEST-- +SPL: ArrayIterator implementing RecursiveIterator +--FILE-- +<?php + +class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator +{ + function hasChildren() + { + return is_array($this->current()); + } + + function getChildren() + { + return new RecursiceArrayIterator($this->current()); + } +} + +$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); + +$dir = new RecursiveIteratorIterator(new RecursiceArrayIterator($array), RIT_LEAVES_ONLY); + +foreach ($dir as $file) { + print "$file\n"; +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +1 +21 +221 +222 +231 +3 +===DONE=== http://cvs.php.net/diff.php/php-src/ext/spl/tests/array_011.phpt?r1=1.1&r2=1.2&ty=u Index: php-src/ext/spl/tests/array_011.phpt diff -u php-src/ext/spl/tests/array_011.phpt:1.1 php-src/ext/spl/tests/array_011.phpt:1.2 --- php-src/ext/spl/tests/array_011.phpt:1.1 Sun Apr 25 07:14:11 2004 +++ php-src/ext/spl/tests/array_011.phpt Wed Apr 28 15:58:47 2004 @@ -1,37 +1,37 @@ ---TEST-- -SPL: ArrayIterator, LimitIterator and string keys +--TEST-- +SPL: ArrayIterator, LimitIterator and string keys --SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$a = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5); -//foreach (new ArrayIterator($a) as $k => $v) -foreach (new LimitIterator(new ArrayIterator($a), 1, 3) as $k => $v) -{ - var_dump(array($k, $v)); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -array(2) { - [0]=> - string(3) "one" - [1]=> - int(1) -} -array(2) { - [0]=> - string(3) "two" - [1]=> - int(2) -} -array(2) { - [0]=> - string(5) "three" - [1]=> - int(3) -} -===DONE=== +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +$a = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5); +//foreach (new ArrayIterator($a) as $k => $v) +foreach (new LimitIterator(new ArrayIterator($a), 1, 3) as $k => $v) +{ + var_dump(array($k, $v)); +} + +?> +===DONE=== +<?php exit(0); ?> +--EXPECT-- +array(2) { + [0]=> + string(3) "one" + [1]=> + int(1) +} +array(2) { + [0]=> + string(3) "two" + [1]=> + int(2) +} +array(2) { + [0]=> + string(5) "three" + [1]=> + int(3) +} +===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_001.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_001.phpt +++ php-src/ext/spl/tests/iterator_001.phpt --TEST-- SPL: Iterator aggregating inner iterator's methods --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php class NumericArrayIterator implements Iterator { protected $a; protected $i = 0; public function __construct($a) { echo __METHOD__ . "\n"; $this->a = $a; } public function rewind() { echo __METHOD__ . "\n"; $this->i = 0; } public function valid() { $ret = $this->i < count($this->a); echo __METHOD__ . '(' . ($ret ? 'true' : 'false') . ")\n"; return $ret; } public function key() { echo __METHOD__ . "\n"; return $this->i; } public function current() { echo __METHOD__ . "\n"; return $this->a[$this->i]; } public function next() { echo __METHOD__ . "\n"; $this->i++; } public function greaterThen($comp) { echo get_class($this) . '::' . __FUNCTION__ . '(' . $comp . ")\n"; return $this->current() > $comp; } } class SeekableNumericArrayIterator extends NumericArrayIterator implements SeekableIterator { public function seek($index) { if ($index < count($this->a)) { $this->i = $index; } echo __METHOD__ . '(' . $index . ")\n"; } } $a = array(1, 2, 3, 4, 5); $it = new LimitIterator(new NumericArrayIterator($a), 1, 3); foreach ($it as $v) { print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } echo "===SEEKABLE===\n"; $a = array(1, 2, 3, 4, 5); $it = new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3); foreach($it as $v) { print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } echo "===STACKED===\n"; $a = array(1, 2, 3, 4, 5); $it = new CachingIterator(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3)); foreach($it as $v) { print $v . ' is ' . ($it->greaterThen(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- NumericArrayIterator::__construct NumericArrayIterator::rewind NumericArrayIterator::valid(true) NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 2 is less than or equal 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 3 is greater than 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 4 is greater than 2 NumericArrayIterator::next ===SEEKABLE=== NumericArrayIterator::__construct NumericArrayIterator::rewind SeekableNumericArrayIterator::seek(1) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 2 is less than or equal 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 3 is greater than 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key LimitIterator::greaterThen(2) 4 is greater than 2 NumericArrayIterator::next ===STACKED=== NumericArrayIterator::__construct NumericArrayIterator::rewind SeekableNumericArrayIterator::seek(1) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key CachingIterator::greaterThen(2) 2 is less than or equal 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key CachingIterator::greaterThen(2) 3 is greater than 2 NumericArrayIterator::next CachingIterator::greaterThen(2) 4 is greater than 2 ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_002.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_002.phpt +++ php-src/ext/spl/tests/iterator_002.phpt --TEST-- SPL: Iterator using getInnerIterator --FILE-- <?php class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator { function hasChildren() { return is_array($this->current()); } function getChildren() { return new RecursiceArrayIterator($this->current()); } } class CrashIterator extends FilterIterator implements RecursiveIterator { function accept() { return true; } function hasChildren() { return $this->getInnerIterator()->hasChildren(); } function getChildren() { return new RecursiceArrayIterator($this->getInnerIterator()->current()); } } $array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); $dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RIT_LEAVES_ONLY); foreach ($dir as $file) { print "$file\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- 1 21 221 222 231 3 ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_003.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_003.phpt +++ php-src/ext/spl/tests/iterator_003.phpt --TEST-- SPL: CachingIterator and __toString() --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php class Student { private $id; private $name; public function __construct($id, $name) { $this->id = $id; $this->name = $name; } public function __toString() { return $this->id . ', ' . $this->name; } public function getId() { return $this->id; } } class StudentIdFilter extends FilterIterator { private $id; public function __construct(ArrayObject $students, Student $other) { FilterIterator::__construct($students->getIterator()); $this->id = $other->getId(); } public function accept() { echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n"; return $this->current()->getId() == $this->id; } } class StudentList implements IteratorAggregate { private $students; public function __construct() { $this->students = new ArrayObject(array()); } public function add(Student $student) { if (!$this->contains($student)) { $this->students[] = $student; } } public function contains(Student $student) { foreach ($this->students as $s) { if ($s->getId() == $student->getId()) { return true; } } return false; } public function getIterator() { return new CachingIterator($this->students->getIterator(), true); } } $students = new StudentList(); $students->add(new Student('01234123', 'Joe')); $students->add(new Student('00000014', 'Bob')); $students->add(new Student('00000014', 'Foo')); // The goal is to verify we can access the cached string value even if it was // generated by a call to __toString(). To check this we need to access the // iterator's __toString() method. $it = $students->getIterator(); foreach ($it as $student) { echo $it->__toString(), "\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- 01234123, Joe 00000014, Bob ===DONE=== http://cvs.php.net/co.php/php-src/ext/spl/tests/iterator_004.phpt?r=1.1&p=1 Index: php-src/ext/spl/tests/iterator_004.phpt +++ php-src/ext/spl/tests/iterator_004.phpt --TEST-- SPL: SeekableIterator and string keys --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php class NumericArrayIterator implements Iterator { protected $a; protected $i; public function __construct($a) { echo __METHOD__ . "\n"; $this->a = $a; } public function rewind() { echo __METHOD__ . "\n"; $this->i = 0; } public function valid() { $ret = $this->i < count($this->a); echo __METHOD__ . '(' . ($ret ? 'true' : 'false') . ")\n"; return $ret; } public function key() { echo __METHOD__ . "\n"; return $this->i; } public function current() { echo __METHOD__ . "\n"; return $this->a[$this->i]; } public function next() { echo __METHOD__ . "\n"; $this->i++; } } class SeekableNumericArrayIterator extends NumericArrayIterator implements SeekableIterator { public function seek($index) { if ($index < count($this->a)) { $this->i = $index; } echo __METHOD__ . '(' . $index . ")\n"; } } $a = array(1, 2, 3, 4, 5); foreach (new LimitIterator(new NumericArrayIterator($a), 1, 3) as $v) { print "$v\n"; } echo "===SEEKABLE===\n"; $a = array(1, 2, 3, 4, 5); foreach(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3) as $v) { print "$v\n"; } echo "===SEEKING===\n"; $a = array(1, 2, 3, 4, 5); $l = new LimitIterator(new SeekableNumericArrayIterator($a)); for($i = 1; $i < 4; $i++) { $l->seek($i); print $l->current() . "\n"; } ?> ===DONE=== <?php exit(0); ?> --EXPECT-- NumericArrayIterator::__construct NumericArrayIterator::rewind NumericArrayIterator::valid(true) NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 3 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 4 NumericArrayIterator::next ===SEEKABLE=== NumericArrayIterator::__construct NumericArrayIterator::rewind SeekableNumericArrayIterator::seek(1) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 2 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 3 NumericArrayIterator::next NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 4 NumericArrayIterator::next ===SEEKING=== NumericArrayIterator::__construct SeekableNumericArrayIterator::seek(1) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 2 SeekableNumericArrayIterator::seek(2) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 3 SeekableNumericArrayIterator::seek(3) NumericArrayIterator::valid(true) NumericArrayIterator::current NumericArrayIterator::key 4 ===DONE===
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php