SPL-StandardPHPLibrary
Public Member Functions | Public Attributes | List of all members
DirectoryTreeIterator Class Reference
Inheritance diagram for DirectoryTreeIterator:
Inheritance graph
Collaboration diagram for DirectoryTreeIterator:
Collaboration graph

Public Member Functions

 __call ($func, $params)
 
 __construct ($path)
 
 beginChildren ()
 
 callGetChildren ()
 
 callHasChildren ()
 
 current ()
 
 endChildren ()
 
 getDepth ()
 
 getInnerIterator ()
 
 getSubIterator ($level=NULL)
 
 key ()
 
 next ()
 
 nextElement ()
 
 rewind ()
 
 valid ()
 

Public Attributes

const CATCH_GET_CHILD = 0x00000002
 
const CHILD_FIRST = 2
 
const LEAVES_ONLY = 0
 
const SELF_FIRST = 1
 

Detailed Description

DirectoryIterator to generate ASCII graphic directory trees.

Author
Marcus Boerger
Version
1.1

Definition at line 17 of file directorytreeiterator.inc.

Constructor & Destructor Documentation

DirectoryTreeIterator::__construct (   $path)

Construct from a path.

Parameters
$pathdirectory to iterate

Definition at line 22 of file directorytreeiterator.inc.

References CachingIterator\CALL_TOSTRING, CachingIterator\CATCH_GET_CHILD, and RecursiveDirectoryIterator\KEY_AS_FILENAME.

23  {
24  parent::__construct(
27  ),
29  ),
30  parent::SELF_FIRST
31  );
32  }
Cached recursive iteration over another Iterator.
recursive directory iterator
Definition: spl.php:1034

Member Function Documentation

DirectoryTreeIterator::__call (   $func,
  $params 
)

Aggregates the inner iterator.

Definition at line 48 of file directorytreeiterator.inc.

References RecursiveIteratorIterator\getSubIterator().

49  {
50  return call_user_func_array(array($this->getSubIterator(), $func), $params);
51  }

Here is the call graph for this function:

RecursiveIteratorIterator::beginChildren ( )
inherited

Called right after calling getChildren() and its rewind().

Since
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\next().

202  {
203  }
RecursiveIteratorIterator::callGetChildren ( )
inherited
Returns
current sub iterators current children
Since
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count.

Referenced by RecursiveIteratorIterator\next().

194  {
195  return $this->ait[$this->count]->getChildren();
196  }
RecursiveIteratorIterator::callHasChildren ( )
inherited
Returns
whether current sub iterators current element has children
Since
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count.

Referenced by RecursiveIteratorIterator\callNextElement(), and RecursiveIteratorIterator\next().

186  {
187  return $this->ait[$this->count]->hasChildren();
188  }
DirectoryTreeIterator::current ( )
Returns
the current element prefixed with ASCII graphics

Implements Iterator.

Definition at line 36 of file directorytreeiterator.inc.

References RecursiveIteratorIterator\getDepth(), and RecursiveIteratorIterator\getSubIterator().

37  {
38  $tree = '';
39  for ($l=0; $l < $this->getDepth(); $l++) {
40  $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' ';
41  }
42  return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
43  . $this->getSubIterator($l)->__toString();
44  }

Here is the call graph for this function:

RecursiveIteratorIterator::endChildren ( )
inherited

Called after current child iterator is invalid and right before it gets destructed.

Since
PHP 5.1

Definition at line 209 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\next(), RecursiveIteratorIterator\rewind(), and RecursiveIteratorIterator\valid().

210  {
211  }
RecursiveIteratorIterator::getDepth ( )
inherited
Returns
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

Referenced by current(), and RecursiveTreeIterator\getPrefix().

178  {
179  return $this->level;
180  }
RecursiveIteratorIterator::getInnerIterator ( )
inherited
Returns
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

References $it.

Referenced by RecursiveCompareDualIterator\areEqual(), RecursiveCompareDualIterator\areIdentical(), and RecursiveCompareDualIterator\endChildren().

171  {
172  return $this->it;
173  }
$it
Definition: class_tree.php:105
RecursiveIteratorIterator::getSubIterator (   $level = NULL)
inherited
Returns
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count.

Referenced by __call(), RecursiveTreeIterator\__call(), current(), and RecursiveTreeIterator\getPrefix().

160  {
161  if (is_null($level)) {
162  $level = $this->count;
163  }
164  return @$this->ait[$level];
165  }
RecursiveIteratorIterator::key ( )
inherited
Returns
current key

Implements Iterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, and $it.

92  {
93  $it = $this->ait[$this->count];
94  return $it->key();
95  }
$it
Definition: class_tree.php:105
RecursiveIteratorIterator::next ( )
inherited

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, $it, RecursiveIteratorIterator\beginChildren(), RecursiveIteratorIterator\callGetChildren(), RecursiveIteratorIterator\callHasChildren(), RecursiveIteratorIterator\callNextElement(), and RecursiveIteratorIterator\endChildren().

108  {
109  while ($this->count) {
110  $it = $this->ait[$this->count];
111  if ($it->valid()) {
112  if (!$it->recursed && callHasChildren()) {
113  $it->recursed = true;
114  try
115  {
116  $sub = callGetChildren();
117  }
118  catch (Exception $e)
119  {
120  if (!($this->flags & self::CATCH_GET_CHILD))
121  {
122  throw $e;
123  }
124  $it->next();
125  continue;
126  }
127  $sub->recursed = false;
128  $sub->rewind();
129  if ($sub->valid()) {
130  $this->ait[++$this->count] = $sub;
131  if (!$sub instanceof RecursiveIterator) {
132  throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
133  }
134  $this->beginChildren();
135  return;
136  }
137  unset($sub);
138  }
139  $it->next();
140  $it->recursed = false;
141  if ($it->valid()) {
142  return;
143  }
144  $it->recursed = false;
145  }
146  if ($this->count) {
147  unset($this->ait[$this->count--]);
148  $it = $this->ait[$this->count];
149  $this->endChildren();
150  callNextElement(false);
151  }
152  }
153  callNextElement(true);
154  }
$it
Definition: class_tree.php:105
Interface for recursive iteration with RecursiveIteratorIterator.
beginChildren()
Called right after calling getChildren() and its rewind().
Basic Exception class.
Definition: spl.php:258
endChildren()
Called after current child iterator is invalid and right before it gets destructed.

Here is the call graph for this function:

RecursiveIteratorIterator::nextElement ( )
inherited

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\callNextElement().

233  {
234  }
RecursiveIteratorIterator::rewind ( )
inherited

Rewind to top iterator as set in constructor.

Implements Iterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\callNextElement(), and RecursiveIteratorIterator\endChildren().

63  {
64  while ($this->count) {
65  unset($this->ait[$this->count--]);
66  $this->endChildren();
67  }
68  $this->ait[0]->rewind();
69  $this->ait[0]->recursed = false;
70  callNextElement(true);
71  }
endChildren()
Called after current child iterator is invalid and right before it gets destructed.

Here is the call graph for this function:

RecursiveIteratorIterator::valid ( )
inherited
Returns
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, $it, and RecursiveIteratorIterator\endChildren().

Referenced by RecursiveIteratorIterator\callNextElement().

76  {
78  while ($count) {
79  $it = $this->ait[$count];
80  if ($it->valid()) {
81  return true;
82  }
83  $count--;
84  $this->endChildren();
85  }
86  return false;
87  }
$it
Definition: class_tree.php:105
endChildren()
Called after current child iterator is invalid and right before it gets destructed.

Here is the call graph for this function:

Member Data Documentation

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002
inherited

Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 33 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::CHILD_FIRST = 2
inherited

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::LEAVES_ONLY = 0
inherited

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::SELF_FIRST = 1
inherited

Mode: Show parents prior to their children.

Definition at line 27 of file recursiveiteratoriterator.inc.


The documentation for this class was generated from the following file: