From: Marcus Boerger Date: Sun, 2 Oct 2005 17:33:05 +0000 (+0000) Subject: - MFH Add new example X-Git-Tag: php-5.1.0RC2~135 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ea0e1615f8892c3f024418c69b2398bd949b619;p=php - MFH Add new example --- diff --git a/ext/spl/examples/recursivetreeiterator.inc b/ext/spl/examples/recursivetreeiterator.inc new file mode 100755 index 0000000000..169b3a8022 --- /dev/null +++ b/ext/spl/examples/recursivetreeiterator.inc @@ -0,0 +1,48 @@ +callToString = (bool)($cit_flags & CachingIterator::CALL_TOSTRING); + } + + /** @return the current element prefixed with ASCII graphics + */ + function current() + { + $tree = ''; + for ($l=0; $l < $this->getDepth(); $l++) { + $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' '; + } + + return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') + . ($this->callToString ? $this->getSubIterator($l)->__toString() : $this->getSubIterator($l)->current()); + } + + /** Aggregates the inner iterator + */ + function __call($func, $params) + { + return call_user_func_array(array($this->getSubIterator(), $func), $params); + } +}