Back to index

php5  5.3.10
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
RecursiveIteratorIterator Class Reference

Iterates through recursive iterators. More...

Inheritance diagram for RecursiveIteratorIterator:
Inheritance graph
[legend]
Collaboration diagram for RecursiveIteratorIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 __construct (RecursiveIterator $it, $mode=self::LEAVES_ONLY, $flags=0)
 Construct from RecursiveIterator.
 rewind ()
 Rewind to top iterator as set in constructor.
 valid ()
 key ()
 current ()
 next ()
 Forward to next element.
 getSubIterator ($level=NULL)
 getInnerIterator ()
 getDepth ()
 callHasChildren ()
 callGetChildren ()
 beginChildren ()
 Called right after calling getChildren() and its rewind().
 endChildren ()
 Called after current child iterator is invalid and right before it gets destructed.
 nextElement ()
 Called when the next element is available.

Public Attributes

const LEAVES_ONLY = 0
 Mode: Only show leaves.
const SELF_FIRST = 1
 Mode: Show parents prior to their children.
const CHILD_FIRST = 2
 Mode: Show all children prior to their parent.
const CATCH_GET_CHILD = 0x00000002
 Flag: Catches exceptions during getChildren() calls and simply jumps to the next element.

Private Member Functions

 callNextElement ($after_move)

Private Attributes

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

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:
itRecursiveIterator to iterate
modeOperation 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
flagsControl 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.

       {
              $this->ait[0] = $it;
              $this->mode   = $mode;
              $this->flags  = $flags;
       }

Member Function Documentation

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

Since:
PHP 5.1

Definition at line 201 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Returns:
current sub iterators current children
Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

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

Here is the caller graph for this function:

Returns:
whether current sub iterators current element has children
Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

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

Here is the caller graph for this function:

RecursiveIteratorIterator::callNextElement ( after_move) [private]

Definition at line 213 of file recursiveiteratoriterator.inc.

       {
              if ($this->valid())
              {
                     if ($after_move)
                     {
                            if (($this->mode == self::SELF_FIRST && $this->callHasChildren())
                            ||   $this->mode == self::LEAVES_ONLY)
                            $this->nextElement();
                     }
                     else
                     {
                            $this->nextElement();
                     }
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
current element

Implements Iterator.

Reimplemented in RecursiveTreeIterator, DirectoryTreeIterator, and DirectoryTreeIterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

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

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.

       {
       }

Here is the caller graph for this function:

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

       {
              return $this->level;
       }

Here is the caller graph for this function:

Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

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

Definition at line 159 of file recursiveiteratoriterator.inc.

       {
              if (is_null($level)) {
                     $level = $this->count;
              }
              return @$this->ait[$level];
       }

Here is the caller graph for this function:

Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

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

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     $it = $this->ait[$this->count];
                     if ($it->valid()) {
                            if (!$it->recursed && callHasChildren()) {
                                   $it->recursed = true;
                                   try
                                   {
                                          $sub = callGetChildren();
                                   }
                                   catch (Exception $e)
                                   {
                                          if (!($this->flags & self::CATCH_GET_CHILD))
                                          {
                                                 throw $e;
                                          }
                                          $it->next();
                                          continue;
                                   }
                                   $sub->recursed = false;
                                   $sub->rewind();
                                   if ($sub->valid()) {
                                          $this->ait[++$this->count] = $sub;
                                          if (!$sub instanceof RecursiveIterator) {
                                                 throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
                                          }
                                          $this->beginChildren();
                                          return;
                                   }
                                   unset($sub);
                            }
                            $it->next();
                            $it->recursed = false;
                            if ($it->valid()) {
                                   return;
                            }
                            $it->recursed = false;
                     }
                     if ($this->count) {
                            unset($this->ait[$this->count--]);
                            $it = $this->ait[$this->count];
                            $this->endChildren();
                            callNextElement(false);
                     }
              }
              callNextElement(true);
       }

Here is the call graph for this function:

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

       {
       }

Here is the caller graph for this function:

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

       {
              while ($this->count) {
                     unset($this->ait[$this->count--]);
                     $this->endChildren();
              }
              $this->ait[0]->rewind();
              $this->ait[0]->recursed = false;
              callNextElement(true);
       }

Here is the call graph for this function:

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 75 of file recursiveiteratoriterator.inc.

       {
              $count = $this->count;
              while ($count) {
                     $it = $this->ait[$count];
                     if ($it->valid()) {
                            return true;
                     }
                     $count--;
                     $this->endChildren();
              }
              return false;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

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

Definition at line 35 of file recursiveiteratoriterator.inc.

Definition at line 36 of file recursiveiteratoriterator.inc.

Definition at line 38 of file recursiveiteratoriterator.inc.

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

Definition at line 37 of file recursiveiteratoriterator.inc.

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

Definition at line 33 of file recursiveiteratoriterator.inc.

Mode: Show all children prior to their parent.

Definition at line 29 of file recursiveiteratoriterator.inc.

Mode: Only show leaves.

Definition at line 25 of file recursiveiteratoriterator.inc.

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: