RecursiveTreeIterator Class Reference
[Example classes]

RecursiveIteratorIterator to generate ASCII graphic trees for the entries in a RecursiveIterator. More...

Inheritance diagram for RecursiveTreeIterator:

Inheritance graph
{RecursiveIteratorIterator\n|+ CATCH_GET_CHILD\l+ CHILD_FIRST\l+ LEAVES_ONLY\l+ SELF_FIRST\l- $ait\l- $count\l- $flags\l- $mode\l|+ __construct()\l+ beginChildren()\l+ callGetChildren()\l+ callHasChildren()\l+ current()\l+ endChildren()\l+ getDepth()\l+ getInnerIterator()\l+ getSubIterator()\l+ key()\l+ next()\l+ nextElement()\l+ rewind()\l+ valid()\l- callNextElement()\l}{OuterIterator\n||+ getInnerIterator()\l}{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}
[legend]
Collaboration diagram for RecursiveTreeIterator:

Collaboration graph
{RecursiveIteratorIterator\n|+ CATCH_GET_CHILD\l+ CHILD_FIRST\l+ LEAVES_ONLY\l+ SELF_FIRST\l- $ait\l- $count\l- $flags\l- $mode\l|+ __construct()\l+ beginChildren()\l+ callGetChildren()\l+ callHasChildren()\l+ current()\l+ endChildren()\l+ getDepth()\l+ getInnerIterator()\l+ getSubIterator()\l+ key()\l+ next()\l+ nextElement()\l+ rewind()\l+ valid()\l- callNextElement()\l}{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

 __call ($func, $params)
 __construct (RecursiveIterator $it, $rit_flags=self::BYPASS_KEY, $cit_flags=CachingIterator::CATCH_GET_CHILD, $mode=self::SELF_FIRST)
 beginChildren ()
 callGetChildren ()
 callHasChildren ()
 current ()
 endChildren ()
 getDepth ()
 getEntry ()
 getInnerIterator ()
 getPostfix ()
 getPrefix ()
 getSubIterator ($level=NULL)
 key ()
 next ()
 nextElement ()
 rewind ()
 valid ()

Public Attributes

 $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>'')
const BYPASS_CURRENT = 0x00000004
const BYPASS_KEY = 0x00000008
const CATCH_GET_CHILD = 0x00000002
const CHILD_FIRST = 2
const LEAVES_ONLY = 0
const SELF_FIRST = 1

Private Attributes

 $rit_flags

Detailed Description

RecursiveIteratorIterator to generate ASCII graphic trees for the entries in a RecursiveIterator.

Author:
Marcus Boerger, Johannes Schlueter
Version:
1.0

Definition at line 19 of file recursivetreeiterator.inc.


Constructor & Destructor Documentation

RecursiveTreeIterator::__construct ( RecursiveIterator it,
rit_flags = self::BYPASS_KEY,
cit_flags = CachingIterator::CATCH_GET_CHILD,
mode = self::SELF_FIRST 
)

Parameters:
it iterator to use as inner iterator

Parameters:
rit_flags flags passed to RecursiveIteratoIterator (parent)
cit_flags flags passed to RecursiveCachingIterator (for hasNext)
mode mode passed to RecursiveIteratoIterator (parent)

Definition at line 32 of file recursivetreeiterator.inc.

References $it, RecursiveIteratorIterator::$mode, and $rit_flags.

00033     {
00034         parent::__construct(new RecursiveCachingIterator($it, $cit_flags), $mode, $rit_flags);
00035         $this->rit_flags = $rit_flags;
00036     }


Member Function Documentation

RecursiveTreeIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 107 of file recursivetreeiterator.inc.

References RecursiveIteratorIterator::getSubIterator().

00108     {
00109         return call_user_func_array(array($this->getSubIterator(), $func), $params);
00110     }

Here is the call graph for this function:

RecursiveIteratorIterator::getSubIterator

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().

00202     {
00203     }

RecursiveIteratorIterator::callGetChildren (  )  [inherited]

Returns:
current sub iterators current children

Since:
PHP 5.1

Definition at line 193 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator::next().

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

RecursiveIteratorIterator::callHasChildren (  )  [inherited]

Returns:
whether current sub iterators current element has children

Since:
PHP 5.1

Definition at line 185 of file recursiveiteratoriterator.inc.

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

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

RecursiveTreeIterator::current (  ) 

Returns:
the current element prefixed and postfixed

Reimplemented from RecursiveIteratorIterator.

Definition at line 79 of file recursivetreeiterator.inc.

References getEntry(), getPostfix(), and getPrefix().

00080     {
00081         if ($this->rit_flags & self::BYPASS_CURRENT)
00082         {
00083             return parent::current();
00084         }
00085         else
00086         {
00087             return $this->getPrefix() . $this->getEntry() .  $this->getPostfix();
00088         }
00089     }

Here is the call graph for this function:

RecursiveTreeIterator::getEntryRecursiveTreeIterator::getPostfixRecursiveTreeIterator::getPrefixRecursiveIteratorIterator::getDepthRecursiveIteratorIterator::getSubIterator

RecursiveIteratorIterator::endChildren (  )  [inherited]

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 RecursiveIteratorIterator::next(), RecursiveIteratorIterator::rewind(), and RecursiveIteratorIterator::valid().

00210     {
00211     }

RecursiveIteratorIterator::getDepth (  )  [inherited]

Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

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

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

RecursiveTreeIterator::getEntry (  ) 

Returns:
string presentation build for current element

Definition at line 65 of file recursivetreeiterator.inc.

Referenced by current().

00066     {
00067         return @(string)parent::current();
00068     }

RecursiveIteratorIterator::getInnerIterator (  )  [inherited]

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     }

RecursiveTreeIterator::getPostfix (  ) 

Returns:
string to place after the current element

Definition at line 72 of file recursivetreeiterator.inc.

Referenced by current(), and key().

00073     {
00074         return '';
00075     }

RecursiveTreeIterator::getPrefix (  ) 

Returns:
string to place in front of current element

Definition at line 51 of file recursivetreeiterator.inc.

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

Referenced by current(), and key().

00052     {
00053         $tree = '';
00054         for ($level = 0; $level < $this->getDepth(); $level++)
00055         {
00056             $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2];
00057         }
00058         $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4];
00059 
00060         return $this->prefix[0] . $tree . $this->prefix[5];
00061     }

Here is the call graph for this function:

RecursiveIteratorIterator::getDepthRecursiveIteratorIterator::getSubIterator

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.

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

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

RecursiveTreeIterator::key (  ) 

Returns:
the current key prefixed and postfixed

Reimplemented from RecursiveIteratorIterator.

Definition at line 93 of file recursivetreeiterator.inc.

References getPostfix(), and getPrefix().

00094     {
00095         if ($this->rit_flags & self::BYPASS_KEY)
00096         {
00097             return parent::key();
00098         }
00099         else
00100         {
00101             return $this->getPrefix() . parent::key() .  $this->getPostfix();
00102         }
00103     }

Here is the call graph for this function:

RecursiveTreeIterator::getPostfixRecursiveTreeIterator::getPrefixRecursiveIteratorIterator::getDepthRecursiveIteratorIterator::getSubIterator

RecursiveIteratorIterator::next (  )  [inherited]

Forward to next element.

Implements Iterator.

Definition at line 107 of file recursiveiteratoriterator.inc.

References $it, RecursiveIteratorIterator::beginChildren(), RecursiveIteratorIterator::callGetChildren(), RecursiveIteratorIterator::callHasChildren(), RecursiveIteratorIterator::callNextElement(), RecursiveIteratorIterator::endChildren(), and RecursiveIteratorIterator::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 (  )  [inherited]

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator::callNextElement().

00233     {
00234     }

RecursiveIteratorIterator::rewind (  )  [inherited]

Rewind to top iterator as set in constructor.

Implements Iterator.

Reimplemented in RecursiveCompareDualIterator.

Definition at line 62 of file recursiveiteratoriterator.inc.

References RecursiveIteratorIterator::callNextElement(), and RecursiveIteratorIterator::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 (  )  [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(), and RecursiveIteratorIterator::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

RecursiveTreeIterator::$prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>'')

Prefix strings used in getPrefix().

0: prefix used to start elements 1: prefix used if $level < depth and hasNext($level) == true 2: prefix used if $level < depth and hasNext($level) == false 3: prefix used if $level == depth and hasNext($level) == true 4: prefix used if $level == depth and hasNext($level) == false 5: prefix used right in front of the current element

Definition at line 47 of file recursivetreeiterator.inc.

RecursiveTreeIterator::$rit_flags [private]

Definition at line 24 of file recursivetreeiterator.inc.

Referenced by __construct().

const RecursiveTreeIterator::BYPASS_CURRENT = 0x00000004

Definition at line 21 of file recursivetreeiterator.inc.

const RecursiveTreeIterator::BYPASS_KEY = 0x00000008

Definition at line 22 of file recursivetreeiterator.inc.

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