From eedd7b36d2f40af9261ab7326628fa9cee8a1059 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 2 Oct 2005 17:32:36 +0000 Subject: [PATCH] - Add new example --- ext/spl/examples/recursivetreeiterator.inc | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 ext/spl/examples/recursivetreeiterator.inc 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); + } +} -- 2.50.1