From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- ext/spl/internal/recursivetreeiterator.inc | 132 +++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 ext/spl/internal/recursivetreeiterator.inc (limited to 'ext/spl/internal/recursivetreeiterator.inc') diff --git a/ext/spl/internal/recursivetreeiterator.inc b/ext/spl/internal/recursivetreeiterator.inc new file mode 100644 index 0000000..dfcdc05 --- /dev/null +++ b/ext/spl/internal/recursivetreeiterator.inc @@ -0,0 +1,132 @@ +rit_flags = $rit_flags; + } + + private $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>''); + + /** Prefix used to start elements. */ + const PREFIX_LEFT = 0; + /** Prefix used if $level < depth and hasNext($level) == true. */ + const PREFIX_MID_HAS_NEXT = 1; + /** Prefix used if $level < depth and hasNext($level) == false. */ + const PREFIX_MID_LAST = 2; + /** Prefix used if $level == depth and hasNext($level) == true. */ + const PREFIX_END_HAS_NEXT = 3; + /** Prefix used if $level == depth and hasNext($level) == false. */ + const PREFIX_END_LAST = 4; + /** Prefix used right in front of the current element. */ + const PREFIX_RIGHT = 5; + + /** + * Set prefix part as used in getPrefix() and stored in $prefix. + * @param $part any PREFIX_* const. + * @param $value new prefix string for specified part. + * @throws OutOfRangeException if 0 > $part or $part > 5. + */ + function setPrefixPart($part, $value) + { + if (0 > $part || $part > 5) { + throw new OutOfRangeException(); + } + $this->prefix[$part] = (string)$value; + } + + /** @return string to place in front of current element + */ + function getPrefix() + { + $tree = ''; + for ($level = 0; $level < $this->getDepth(); $level++) + { + $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2]; + } + $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4]; + + return $this->prefix[0] . $tree . $this->prefix[5]; + } + + /** @return string presentation build for current element + */ + function getEntry() + { + return @(string)parent::current(); + } + + /** @return string to place after the current element + */ + function getPostfix() + { + return ''; + } + + /** @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 the current key prefixed and postfixed + */ + function key() + { + if ($this->rit_flags & self::BYPASS_KEY) + { + return parent::key(); + } + else + { + return $this->getPrefix() . parent::key() . $this->getPostfix(); + } + } + + /** Aggregates the inner iterator + */ + function __call($func, $params) + { + return call_user_func_array(array($this->getSubIterator(), $func), $params); + } +} + +?> \ No newline at end of file -- cgit v1.2.1