diff options
author | Marcus Boerger <helly@php.net> | 2005-10-13 19:49:27 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2005-10-13 19:49:27 +0000 |
commit | 4c8afd895a34d4747830751f8be8866400d2cb11 (patch) | |
tree | 157b232e0a107382c77cfc2fcd393fa92f44ef3f | |
parent | 7e2bccf77690c3849b74585ef0ab5c8a3ba2be6b (diff) | |
download | php-git-4c8afd895a34d4747830751f8be8866400d2cb11.tar.gz |
- MFH Add ability to bypass key() surrounding and make that default
-rwxr-xr-x | ext/spl/examples/recursivetreeiterator.inc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/spl/examples/recursivetreeiterator.inc b/ext/spl/examples/recursivetreeiterator.inc index ea3cb6ea7f..42d217fa76 100755 --- a/ext/spl/examples/recursivetreeiterator.inc +++ b/ext/spl/examples/recursivetreeiterator.inc @@ -19,8 +19,8 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator { const BYPASS_CURRENT = 0x00000004; + const BYPASS_KEY = 0x00000008; - private $callToString; private $rit_flags; /** @@ -29,11 +29,10 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator * @param cit_flags flags passed to RecursiveCachingIterator (for hasNext) * @param mode mode passed to RecursiveIteratoIterator (parent) */ - function __construct(RecursiveIterator $it, $rit_flags = 0, $cit_flags = CachingIterator::CATCH_GET_CHILD, $mode = self::SELF_FIRST) + function __construct(RecursiveIterator $it, $rit_flags = self::BYPASS_KEY, $cit_flags = CachingIterator::CATCH_GET_CHILD, $mode = self::SELF_FIRST) { parent::__construct(new RecursiveCachingIterator($it, $cit_flags), $mode, $rit_flags); $this->rit_flags = $rit_flags; - $this->callToString = (bool)($cit_flags & CachingIterator::CALL_TOSTRING); } /** Prefix strings used in getPrefix() @@ -65,7 +64,7 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator */ function getEntry() { - return $this->callToString ? $this->__toString() : parent::current(); + return @(string)parent::current(); } /** @return string to place after the current element @@ -78,14 +77,14 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator /** @return the current element prefixed and postfixed */ function current() - { + { if ($this->rit_flags & self::BYPASS_CURRENT) { return parent::current(); } else { - return $this->getPrefix() . $this->getEntry() . $this->getPostfix(); + return $this->getPrefix() . $this->getEntry() . $this->getPostfix(); } } @@ -93,7 +92,14 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator */ function key() { - return $this->getPrefix() . parent::key() . $this->getPostfix(); + if ($this->rit_flags & self::BYPASS_KEY) + { + return parent::key(); + } + else + { + return $this->getPrefix() . parent::key() . $this->getPostfix(); + } } /** Aggregates the inner iterator |