3 // This doc comment block generated by idl/sysdoc.php
5 * ( excerpt from http://php.net/manual/en/class.recursivetreeiterator.php
8 * Allows iterating over a RecursiveIterator to generate an ASCII graphic
12 class RecursiveTreeIterator
extends RecursiveIteratorIterator
13 implements OuterIterator
{
15 const int BYPASS_CURRENT
= 4;
16 const int BYPASS_KEY
= 8;
17 const int PREFIX_LEFT
= 0;
18 const int PREFIX_MID_HAS_NEXT
= 1;
19 const int PREFIX_MID_LAST
= 2;
20 const int PREFIX_END_HAS_NEXT
= 3;
21 const int PREFIX_END_LAST
= 4;
22 const int PREFIX_RIGHT
= 5;
26 private $prefix = varray
[
28 "| ", // PREFIX_MID_HAS_NEXT
29 " ", // PREFIX_MID_LAST
30 "|-", // PREFIX_END_HAS_NEXT
31 "\\-", // PREFIX_END_LAST
35 private $postfix = "";
37 public function __construct(\HH\Traversable
$it, $flags = null, $cit_flags = null,
39 if ($flags === null) $flags = self
::BYPASS_KEY
;
40 if ($mode === null) $mode = RecursiveIteratorIterator
::SELF_FIRST
;
41 if ($cit_flags === null) $cit_flags = CachingIterator
::CATCH_GET_CHILD
;
43 if ($it is \IteratorAggregate
) {
44 $it = $it->getIterator();
47 $this->flags
= $flags;
49 $cachingIterator = new RecursiveCachingIterator($it, $cit_flags);
50 parent
::__construct($cachingIterator, $mode);
53 public function setPrefixPart($part, $prefix) {
54 if ($part < 0 ||
$part > 5) {
55 throw new OutOfRangeException(
56 "Use RecursiveTreeIterator::PREFIX_* constant"
59 $this->prefix
[$part] = (string)$prefix;
62 public function getPrefix() {
63 $return = $this->prefix
[self
::PREFIX_LEFT
];
64 $depth = $this->getDepth();
65 for ($i = 0; $i < $depth; ++
$i) {
66 $hasNext = $this->getSubIterator($i)->hasNext();
68 $return .= $this->prefix
[self
::PREFIX_MID_HAS_NEXT
];
70 $return .= $this->prefix
[self
::PREFIX_MID_LAST
];
74 $hasNext = $this->getSubIterator($i)->hasNext();
76 $return .= $this->prefix
[self
::PREFIX_END_HAS_NEXT
];
78 $return .= $this->prefix
[self
::PREFIX_END_LAST
];
81 $return .= $this->prefix
[self
::PREFIX_RIGHT
];
85 public function setPostfix($postfix) {
86 $this->postfix
= (string)$postfix;
89 public function getEntry() {
90 $current = $this->getInnerIterator()->current();
91 if (is_array($current)) {
94 return (string)$current;
98 public function getPostfix() {
99 return $this->postfix
;
102 public function current() {
103 if ($this->flags
& self
::BYPASS_CURRENT
) {
104 $depth = $this->getDepth();
105 return $this->getSubIterator($depth)->current();
108 $prefix = $this->getPrefix();
109 $entry = $this->getEntry();
110 return $prefix . $entry . $this->postfix
;
113 public function key() {
114 $depth = $this->getDepth();
115 $it = $this->getSubIterator($depth);
117 if ($this->flags
& self
::BYPASS_KEY
) {
121 $prefix = $this->getPrefix();
122 return $prefix . $key . $this->postfix
;