diff options
| author | Marcus Boerger <helly@php.net> | 2005-09-15 03:33:04 +0000 |
|---|---|---|
| committer | Marcus Boerger <helly@php.net> | 2005-09-15 03:33:04 +0000 |
| commit | b4dd030782ae49646cdefa8435e6c8acbbf17745 (patch) | |
| tree | f87f19c742634a48ee644d58a6913cab13ada4d9 /ext/spl/internal | |
| parent | a5f0cbed448d9a057c8cf451074b870e27a335fd (diff) | |
| download | php-git-b4dd030782ae49646cdefa8435e6c8acbbf17745.tar.gz | |
MFH:
- Add SplObjectStorage
- Add RecursiveFilterIterator
- Rename Observer to SplObserver
- Rename Subject to SplSubject
- Move SPL constants to class constants
- Update docu
Diffstat (limited to 'ext/spl/internal')
| -rwxr-xr-x | ext/spl/internal/cachingiterator.inc | 22 | ||||
| -rwxr-xr-x | ext/spl/internal/cachingrecursiveiterator.inc | 10 | ||||
| -rwxr-xr-x | ext/spl/internal/fileobject.inc | 3 | ||||
| -rwxr-xr-x | ext/spl/internal/recursiveiteratoriterator.inc | 54 |
4 files changed, 61 insertions, 28 deletions
diff --git a/ext/spl/internal/cachingiterator.inc b/ext/spl/internal/cachingiterator.inc index dfefd9987f..f5ca2c3c9d 100755 --- a/ext/spl/internal/cachingiterator.inc +++ b/ext/spl/internal/cachingiterator.inc @@ -9,13 +9,10 @@ * SPL - Standard PHP Library */ -define('CIT_CALL_TOSTRING', 1); -define('CIT_CATCH_GET_CHILD', 2); - /** * @brief Cached iteration over another Iterator * @author Marcus Boerger - * @version 1.1 + * @version 1.2 * @since PHP 5.0 * * This iterator wrapper does a one ahead iteration. This way it knows whether @@ -23,13 +20,16 @@ define('CIT_CATCH_GET_CHILD', 2); * * @note If you want to convert the elements into strings and the inner * Iterator is an internal Iterator then you need to provide the - * flag CIT_CALL_TOSTRING to do the conversion when the actual element + * flag CALL_TOSTRING to do the conversion when the actual element * is being fetched. Otherwise the conversion would happen with the * already changed iterator. If you do not need this then it you should * omit this flag because it costs unneccessary work and time. */ class CachingIterator implements OuterIterator { + const CALL_TOSTRING = 1; + const CATCH_GET_CHILD = 2; + private $it; private $current; private $key; @@ -40,12 +40,12 @@ class CachingIterator implements OuterIterator * * @param it Iterator to cache * @param flags Bitmask: - * - CIT_CALL_TOSTRING (whether to call __toString() for every element) + * - CALL_TOSTRING (whether to call __toString() for every element) */ - function __construct(Iterator $it, $flags = CIT_CALL_TOSTRING) + function __construct(Iterator $it, $flags = self::CALL_TOSTRING) { $this->it = $it; - $this->flags = $flags & (CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD); + $this->flags = $flags & (self::CALL_TOSTRING|self::CATCH_GET_CHILD); $this->next(); } @@ -64,7 +64,7 @@ class CachingIterator implements OuterIterator if ($this->valid = $this->it->valid()) { $this->current = $this->it->current(); $this->key = $this->it->key(); - if ($this->flags & CIT_CALL_TOSTRING) { + if ($this->flags & self::CALL_TOSTRING) { if (is_object($this->current)) { $this->strValue = $this->current->__toString(); } else { @@ -119,11 +119,11 @@ class CachingIterator implements OuterIterator /** @return the string represenatation that was generated for the current * element - * @throw exception when CIT_CALL_TOSTRING was not specified in constructor + * @throw exception when CALL_TOSTRING was not specified in constructor */ function __toString() { - if (!$this->flags & CIT_CALL_TOSTRING) { + if (!$this->flags & self::CALL_TOSTRING) { throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); } return $this->strValue; diff --git a/ext/spl/internal/cachingrecursiveiterator.inc b/ext/spl/internal/cachingrecursiveiterator.inc index 72204d9399..5f60d76d5b 100755 --- a/ext/spl/internal/cachingrecursiveiterator.inc +++ b/ext/spl/internal/cachingrecursiveiterator.inc @@ -26,10 +26,10 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera * * @param it Iterator to cache * @param flags Bitmask: - * - CIT_CALL_TOSTRING (whether to call __toString() for every element) - * - CIT_CATCH_GET_CHILD (whether to catch exceptions when trying to get childs) + * - CALL_TOSTRING (whether to call __toString() for every element) + * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs) */ - function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING) + function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING) { parent::__construct($it, $flags); } @@ -56,7 +56,7 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera $this->getChildren = new CachingRecursiveIterator($child, $this->flags); } catch(Exception $e) { - if (!$this->flags & CIT_CATCH_GET_CHILD) { + if (!$this->flags & self::CATCH_GET_CHILD) { throw $e; } $this->hasChildren = false; @@ -70,7 +70,7 @@ class CachingRecursiveIterator extends CachingIterator implements RecursiveItera /** @return whether the current element has children * @note The check whether the Iterator for the children can be created was - * already executed. Hence when flag CIT_CATCH_GET_CHILD was given in + * already executed. Hence when flag CATCH_GET_CHILD was given in * constructor this fucntion returns false so that getChildren does * not try to access those children. */ diff --git a/ext/spl/internal/fileobject.inc b/ext/spl/internal/fileobject.inc index a2f840a4d4..dd27468742 100755 --- a/ext/spl/internal/fileobject.inc +++ b/ext/spl/internal/fileobject.inc @@ -17,6 +17,9 @@ */ class FileObject implements RecursiveIterator, SeekableIterator { + /** Flag: wheter to suppress new lines */ + const DROP_NEW_LINE = 0x00000001; + private $fp; private $fname; private $line = NULL; diff --git a/ext/spl/internal/recursiveiteratoriterator.inc b/ext/spl/internal/recursiveiteratoriterator.inc index b800cd49ae..61a9d60a27 100755 --- a/ext/spl/internal/recursiveiteratoriterator.inc +++ b/ext/spl/internal/recursiveiteratoriterator.inc @@ -9,11 +9,6 @@ * SPL - Standard PHP Library */ -define('RIT_LEAVES_ONLY', 0); -define('RIT_SELF_FIRST', 1); -define('RIT_CHILD_FIRST', 2); -define('RIT_CATCH_GET_CHILD', 2); - /** * @brief Iterates through recursive iterators * @author Marcus Boerger @@ -26,25 +21,36 @@ define('RIT_CATCH_GET_CHILD', 2); */ class RecursiveIteratorIterator implements OuterIterator { + /** Mode: Only show leaves */ + const LEAVES_ONLY = 0; + /** Mode: Show parents prior to their children */ + const SELF_FIRST = 1; + /** Mode: Show all children prior to their parent */ + const CHILD_FIRST = 2; + + /** Flag: Catches exceptions during getChildren() calls and simply jumps + * to the next element. */ + const CATCH_GET_CHILD = 2; + private $ait = array(); private $count = 0; - private $mode = RIT_LEAVES_ONLY; + private $mode = self::LEAVES_ONLY; private $flags = 0; /** Construct from RecursiveIterator * * @param it RecursiveIterator to iterate * @param mode Operation mode (one of): - * - RIT_LEAVES_ONLY only show leaves - * - RIT_SELF_FIRST show parents prior to their childs - * - RIT_CHILD_FIRST show all childs prior to their parent + * - LEAVES_ONLY only show leaves + * - SELF_FIRST show parents prior to their childs + * - CHILD_FIRST show all children prior to their parent * @param flags Control flags, zero or any combination of the following * (since PHP 5.1). - * - RIT_CATCH_GET_CHILD which catches exceptions during + * - CATCH_GET_CHILD which catches exceptions during * getChildren() calls and simply jumps to the next * element. */ - function __construct(RecursiveIterator $it, $mode = RIT_LEAVES_ONLY, $flags = 0) + function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0) { $this->ait[0] = $it; $this->mode = $mode; @@ -61,6 +67,7 @@ class RecursiveIteratorIterator implements OuterIterator } $this->ait[0]->rewind(); $this->ait[0]->recursed = false; + callNextElement(true); } /** @return whether iterator is valid @@ -110,7 +117,7 @@ class RecursiveIteratorIterator implements OuterIterator } catch (Exception $e) { - if (!($this->flags & RIT_CATCH_GET_CHILD)) + if (!($this->flags & self::CATCH_GET_CHILD)) { throw $e; } @@ -140,8 +147,10 @@ class RecursiveIteratorIterator implements OuterIterator unset($this->ait[$this->count--]); $it = $this->ait[$this->count]; $this->endChildren(); + callNextElement(false); } } + callNextElement(true); } /** @return Sub Iterator at given level or if unspecified the current sub @@ -200,6 +209,27 @@ class RecursiveIteratorIterator implements OuterIterator function endChildren() { } + + private function callNextElement($after_move) + { + if ($this->valid()) + { + if ($after_move) + { + if (($this->mode == self::SELF_FIRST && $this->callHasChildren()) + $this->mode == self::LEAVES_ONLY) + $this->nextElement(); + } + else + { + $this->nextElement(); + } + } + } + + /** Called when the next element is available + */ + function nextElement(); } ?>
\ No newline at end of file |
