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

Public Member Functions

 __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

A directory iterator that does not show '.

' and '..'.

Author
Marcus Boerger
Version
1.0

Definition at line 17 of file directorytree.inc.

Constructor & Destructor Documentation

DirectoryTree::__construct (   $path)

Construct from a path.

Parameters
$pathdirectory to iterate

Definition at line 22 of file directorytree.inc.

22  {
23  parent::__construct(new DirectoryFilterDots($path));
24  }
A filtered DirectoryIterator.

Member Function Documentation

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  }
RecursiveIteratorIterator::current ( )
inherited
Returns
current element

Implements Iterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator\$count, and $it.

100  {
101  $it = $this->ait[$this->count];
102  return $it->current();
103  }
$it
Definition: class_tree.php:105
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 DirectoryTreeIterator\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 DirectoryTreeIterator\__call(), RecursiveTreeIterator\__call(), DirectoryTreeIterator\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: