]> granicus.if.org Git - php/commitdiff
- Add ability to bypass key() surrounding and make that default
authorMarcus Boerger <helly@php.net>
Thu, 13 Oct 2005 19:45:29 +0000 (19:45 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 13 Oct 2005 19:45:29 +0000 (19:45 +0000)
ext/spl/examples/recursivetreeiterator.inc

index 2d2210e7047e9a69effb1a6f669ef3c01507bbb0..42d217fa767ed4d91a30e3f97bccfd2908c0fe15 100755 (executable)
@@ -19,6 +19,7 @@
 class RecursiveTreeIterator extends RecursiveIteratorIterator
 {
        const BYPASS_CURRENT = 0x00000004;
+       const BYPASS_KEY     = 0x00000008;
 
        private $rit_flags;
 
@@ -28,7 +29,7 @@ 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;
@@ -91,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