RecursiveIteratorIterator Class Reference

Iterates through recursive iterators. More...

Inheritance diagram for RecursiveIteratorIterator:

Inheritance graph
{DirectoryTree\n||+ __construct()\l}{DirectoryTreeIterator\n||+ __call()\l+ __construct()\l+ current()\l}{RecursiveCompareDualIterator\n|# $equal\l|+ __construct()\l+ areEqual()\l+ areIdentical()\l+ endChildren()\l+ rewind()\l}{RecursiveTreeIterator\n|+ $prefix\l+ BYPASS_CURRENT\l+ BYPASS_KEY\l- $rit_flags\l|+ __call()\l+ __construct()\l+ current()\l+ getEntry()\l+ getPostfix()\l+ getPrefix()\l+ key()\l}{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}{DirectoryGraphIterator\n||+ __construct()\l}
[legend]
Collaboration diagram for RecursiveIteratorIterator:

Collaboration graph
{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
List of all members.

Public Member Functions

 __construct (RecursiveIterator $it, $mode=self::LEAVES_ONLY, $flags=0)
 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

Private Member Functions

 callNextElement ($after_move)

Private Attributes

 $ait = array()
 $count = 0
 $flags = 0
 $mode = self::LEAVES_ONLY

Detailed Description

Iterates through recursive iterators.

Author:
Marcus Boerger
Version:
1.2
Since:
PHP 5.0
The objects of this class are created by instances of RecursiveIterator. Elements of those iterators may be traversable themselves. If so these sub elements are recursed into.

Definition at line 22 of file recursiveiteratoriterator.inc.


Constructor & Destructor Documentation

RecursiveIteratorIterator::__construct ( RecursiveIterator it,
mode = self::LEAVES_ONLY,
flags = 0 
)

Construct from RecursiveIterator.

Parameters:
it RecursiveIterator to iterate
mode Operation mode (one of):
  • LEAVES_ONLY only show leaves
  • SELF_FIRST show parents prior to their childs
  • CHILD_FIRST show all children prior to their parent
flags Control flags, zero or any combination of the following (since PHP 5.1).
  • CATCH_GET_CHILD which catches exceptions during getChildren() calls and simply jumps to the next element.

Definition at line 53 of file recursiveiteratoriterator.inc.

References $flags, $it, and $mode.

Referenced by DirectoryGraphIterator::__construct().

00054     {
00055         $this->ait[0] = $it;
00056         $this->mode   = $mode;
00057         $this->flags  = $flags;
00058     }


Member Function Documentation

RecursiveIteratorIterator::beginChildren (  ) 

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

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

Referenced by next().

00202     {
00203     }

RecursiveIteratorIterator::callGetChildren (  ) 

Returns:
current sub iterators current children

Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

Referenced by next().

00194     {
00195         return $this->ait[$this->count]->getChildren();
00196     }

RecursiveIteratorIterator::callHasChildren (  ) 

Returns:
whether current sub iterators current element has children

Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

Referenced by callNextElement(), and next().

00186     {
00187         return $this->ait[$this->count]->hasChildren();
00188     }

RecursiveIteratorIterator::callNextElement ( after_move  )  [private]

Definition at line 213 of file recursiveiteratoriterator.inc.

References callHasChildren(), nextElement(), and valid().

Referenced by next(), and rewind().

00214     {
00215         if ($this->valid())
00216         {
00217             if ($after_move)
00218             {
00219                 if (($this->mode == self::SELF_FIRST && $this->callHasChildren())
00220                 ||   $this->mode == self::LEAVES_ONLY)
00221                 $this->nextElement();
00222             }
00223             else
00224             {
00225                 $this->nextElement();
00226             }
00227         }
00228     }

Here is the call graph for this function:

RecursiveIteratorIterator::callHasChildrenRecursiveIteratorIterator::nextElementRecursiveIteratorIterator::validRecursiveIteratorIterator::endChildren

RecursiveIteratorIterator::current (  ) 

Returns:
current element

Implements Iterator.

Reimplemented in DirectoryTreeIterator, and RecursiveTreeIterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

References $it.

00100     {
00101         $it = $this->ait[$this->count];
00102         return $it->current();
00103     }

RecursiveIteratorIterator::endChildren (  ) 

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

Since:
PHP 5.1

Reimplemented in RecursiveCompareDualIterator.

Definition at line 209 of file recursiveiteratoriterator.inc.

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

00210     {
00211     }

RecursiveIteratorIterator::getDepth (  ) 

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

Referenced by DirectoryTreeIterator::current(), and RecursiveTreeIterator::getPrefix().

00178     {
00179         return $this->level;
00180     }

RecursiveIteratorIterator::getInnerIterator (  ) 

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

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

00171     {
00172         return $this->it;
00173     }

RecursiveIteratorIterator::getSubIterator ( level = NULL  ) 

Returns:
Sub Iterator at given level or if unspecified the current sub Iterator

Definition at line 159 of file recursiveiteratoriterator.inc.

Referenced by RecursiveTreeIterator::__call(), DirectoryTreeIterator::__call(), DirectoryTreeIterator::current(), and RecursiveTreeIterator::getPrefix().

00160     {
00161         if (is_null($level)) {
00162             $level = $this->count;
00163         }
00164         return @$this->ait[$level];
00165     }

RecursiveIteratorIterator::key (  ) 

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

References $it.

00092     {
00093         $it = $this->ait[$this->count];
00094         return $it->key();
00095     }

RecursiveIteratorIterator::next (  ) 

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

References $it, beginChildren(), callGetChildren(), callHasChildren(), callNextElement(), endChildren(), and valid().

00108     {
00109         while ($this->count) {
00110             $it = $this->ait[$this->count];
00111             if ($it->valid()) {
00112                 if (!$it->recursed && callHasChildren()) {
00113                     $it->recursed = true;
00114                     try
00115                     {
00116                         $sub = callGetChildren();
00117                     }
00118                     catch (Exception $e)
00119                     {
00120                         if (!($this->flags & self::CATCH_GET_CHILD))
00121                         {
00122                             throw $e;
00123                         }
00124                         $it->next();
00125                         continue;
00126                     }
00127                     $sub->recursed = false;
00128                     $sub->rewind();
00129                     if ($sub->valid()) {
00130                         $this->ait[++$this->count] = $sub;
00131                         if (!$sub instanceof RecursiveIterator) {
00132                             throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
00133                         }
00134                         $this->beginChildren();
00135                         return;
00136                     }
00137                     unset($sub);
00138                 }
00139                 $it->next();
00140                 $it->recursed = false;
00141                 if ($it->valid()) {
00142                     return;
00143                 }
00144                 $it->recursed = false;
00145             }
00146             if ($this->count) {
00147                 unset($this->ait[$this->count--]);
00148                 $it = $this->ait[$this->count];
00149                 $this->endChildren();
00150                 callNextElement(false);
00151             }
00152         }
00153         callNextElement(true);
00154     }

Here is the call graph for this function:

RecursiveIteratorIterator::beginChildrenRecursiveIteratorIterator::callGetChildrenRecursiveIteratorIterator::callHasChildrenRecursiveIteratorIterator::callNextElementRecursiveIteratorIterator::validRecursiveIteratorIterator::endChildrenRecursiveIteratorIterator::nextElement

RecursiveIteratorIterator::nextElement (  ) 

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

Referenced by callNextElement().

00233     {
00234     }

RecursiveIteratorIterator::rewind (  ) 

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

References callNextElement(), and endChildren().

00063     {
00064         while ($this->count) {
00065             unset($this->ait[$this->count--]);
00066             $this->endChildren();
00067         }
00068         $this->ait[0]->rewind();
00069         $this->ait[0]->recursed = false;
00070         callNextElement(true);
00071     }

Here is the call graph for this function:

RecursiveIteratorIterator::callNextElementRecursiveIteratorIterator::endChildrenRecursiveIteratorIterator::callHasChildrenRecursiveIteratorIterator::nextElementRecursiveIteratorIterator::valid

RecursiveIteratorIterator::valid (  ) 

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

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

Referenced by callNextElement(), and next().

00076     {
00077         $count = $this->count;
00078         while ($count) {
00079             $it = $this->ait[$count];
00080             if ($it->valid()) {
00081                 return true;
00082             }
00083             $count--;
00084             $this->endChildren();
00085         }
00086         return false;
00087     }

Here is the call graph for this function:

RecursiveIteratorIterator::endChildren


Member Data Documentation

RecursiveIteratorIterator::$ait = array() [private]

Definition at line 35 of file recursiveiteratoriterator.inc.

RecursiveIteratorIterator::$count = 0 [private]

Definition at line 36 of file recursiveiteratoriterator.inc.

Referenced by valid().

RecursiveIteratorIterator::$flags = 0 [private]

Definition at line 38 of file recursiveiteratoriterator.inc.

Referenced by __construct().

RecursiveIteratorIterator::$mode = self::LEAVES_ONLY [private]

Definition at line 37 of file recursiveiteratoriterator.inc.

Referenced by RecursiveTreeIterator::__construct(), and __construct().

const RecursiveIteratorIterator::CATCH_GET_CHILD = 0x00000002

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

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::LEAVES_ONLY = 0

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

const RecursiveIteratorIterator::SELF_FIRST = 1

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:
Generated on Thu Apr 26 01:07:11 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2