helly           Mon Oct  3 09:36:18 2005 EDT

  Modified files:              (Branch: PHP_5_1)
    /php-src/ext/spl/examples   recursivetreeiterator.inc 
  Log:
  - MFH Update example
  
http://cvs.php.net/diff.php/php-src/ext/spl/examples/recursivetreeiterator.inc?r1=1.1.2.2&r2=1.1.2.3&ty=u
Index: php-src/ext/spl/examples/recursivetreeiterator.inc
diff -u php-src/ext/spl/examples/recursivetreeiterator.inc:1.1.2.2 
php-src/ext/spl/examples/recursivetreeiterator.inc:1.1.2.3
--- php-src/ext/spl/examples/recursivetreeiterator.inc:1.1.2.2  Sun Oct  2 
13:33:05 2005
+++ php-src/ext/spl/examples/recursivetreeiterator.inc  Mon Oct  3 09:36:18 2005
@@ -26,17 +26,61 @@
                $this->callToString = (bool)($cit_flags & 
CachingIterator::CALL_TOSTRING);
        }
 
+       /** @return prefix used if $level < depth and hasNext($level) == true
+        */
+       function getPrefix1()
+       {
+               return '| ';
+       }
+
+       /** @return prefix used if $level < depth and hasNext($level) == false
+        */
+       function getPrefix2()
+       {
+               return '  ';
+       }
+
+       /** @return prefix used if $level == depth and hasNext($level) == true
+        */
+       function getPrefix3()
+       {
+               return '|-';
+       }
+
+       /** @return prefix used if $level == depth and hasNext($level) == false
+        */
+       function getPrefix4()
+       {
+               return '\-';
+       }
+
+       function getPrefix($level)
+       {
+               if ($level < 0 || $level > $this->getDepth())
+               {
+                       throw new OutOfBoundsException('Parameter $level must 
be >= 0 and <= depth');
+               }
+               if ($level < $this->getDepth())
+               {
+                       return $this->getSubIterator($level)->hasNext() ? 
$this->getPrefix1() : $this->getPrefix2();
+               }
+               else
+               {
+                       return $this->getSubIterator($level)->hasNext() ? 
$this->getPrefix3() : $this->getPrefix4();
+               }
+       }
+
        /** @return the current element prefixed with ASCII graphics
         */
        function current()
        {
                $tree = '';
-               for ($l=0; $l < $this->getDepth(); $l++) {
-                       $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : 
'  ';
+               for ($l=0; $l <= $this->getDepth(); $l++)
+               {
+                       $tree .= $this->getPrefix($l);
                }
                
-               return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : 
'\-')
-                      . ($this->callToString ? 
$this->getSubIterator($l)->__toString() : $this->getSubIterator($l)->current());
+               return $tree . ($this->callToString ? $this->__toString() : 
parent::current());
        }
 
        /** Aggregates the inner iterator

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to