SPL-StandardPHPLibrary
Public Member Functions | Public Attributes | Private Attributes
RecursiveTreeIterator Class Reference
Inheritance diagram for RecursiveTreeIterator:
Inheritance graph
[legend]
Collaboration diagram for RecursiveTreeIterator:
Collaboration graph
[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 ()
 setPrefixPart ($part, $value)
 valid ()

Public Attributes

const BYPASS_CURRENT = 0x00000004
const BYPASS_KEY = 0x00000008
const CATCH_GET_CHILD = 0x00000002
const CHILD_FIRST = 2
const LEAVES_ONLY = 0
const PREFIX_END_HAS_NEXT = 3
const PREFIX_END_LAST = 4
const PREFIX_LEFT = 0
const PREFIX_MID_HAS_NEXT = 1
const PREFIX_MID_LAST = 2
const PREFIX_RIGHT = 5
const SELF_FIRST = 1

Private Attributes

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

Detailed Description

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

Author:
Marcus Boerger, Johannes Schlueter
Version:
1.1
Since:
PHP 5.3

Definition at line 20 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:
ititerator to use as inner iterator
rit_flagsflags passed to RecursiveIteratoIterator (parent)
cit_flagsflags passed to RecursiveCachingIterator (for hasNext)
modemode passed to RecursiveIteratoIterator (parent)

Definition at line 33 of file recursivetreeiterator.inc.

References RecursiveIteratorIterator\$mode, and $rit_flags.

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

Member Function Documentation

RecursiveTreeIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 126 of file recursivetreeiterator.inc.

References RecursiveIteratorIterator\getSubIterator().

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

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

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

    {
        return $this->ait[$this->count]->getChildren();
    }
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().

    {
        return $this->ait[$this->count]->hasChildren();
    }
RecursiveTreeIterator::current ( )
Returns:
the current element prefixed and postfixed

Reimplemented from RecursiveIteratorIterator.

Definition at line 98 of file recursivetreeiterator.inc.

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

    {
        if ($this->rit_flags & self::BYPASS_CURRENT)
        {
            return parent::current();
        }
        else
        {
            return $this->getPrefix() . $this->getEntry() .  $this->getPostfix();
        }
    }

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

Reimplemented in RecursiveCompareDualIterator.

Definition at line 209 of file recursiveiteratoriterator.inc.

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

    {
    }
RecursiveIteratorIterator::getDepth ( ) [inherited]
Returns:
Current Depth (Number of parents)

Definition at line 177 of file recursiveiteratoriterator.inc.

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

    {
        return $this->level;
    }
RecursiveTreeIterator::getEntry ( )
Returns:
string presentation build for current element

Definition at line 84 of file recursivetreeiterator.inc.

Referenced by current().

    {
        return @(string)parent::current();
    }
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().

    {
        return $this->it;
    }
RecursiveTreeIterator::getPostfix ( )
Returns:
string to place after the current element

Definition at line 91 of file recursivetreeiterator.inc.

Referenced by current(), and key().

    {
        return '';
    }
RecursiveTreeIterator::getPrefix ( )
Returns:
string to place in front of current element

Definition at line 70 of file recursivetreeiterator.inc.

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

Referenced by current(), and key().

    {
        $tree = '';
        for ($level = 0; $level < $this->getDepth(); $level++)
        {
            $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2];
        }
        $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4];

        return $this->prefix[0] . $tree . $this->prefix[5];
    }

Here is the call graph for this function:

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 DirectoryTreeIterator\__call(), __call(), DirectoryTreeIterator\current(), and getPrefix().

    {
        if (is_null($level)) {
            $level = $this->count;
        }
        return @$this->ait[$level];
    }
RecursiveTreeIterator::key ( )
Returns:
the current key prefixed and postfixed

Reimplemented from RecursiveIteratorIterator.

Definition at line 112 of file recursivetreeiterator.inc.

References getPostfix(), and getPrefix().

    {
        if ($this->rit_flags & self::BYPASS_KEY)
        {
            return parent::key();
        }
        else
        {
            return $this->getPrefix() . parent::key() .  $this->getPostfix();
        }
    }

Here is the call graph for this function:

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(), and RecursiveIteratorIterator\endChildren().

    {
        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:

RecursiveIteratorIterator::nextElement ( ) [inherited]

Called when the next element is available.

Definition at line 232 of file recursiveiteratoriterator.inc.

Referenced by RecursiveIteratorIterator\callNextElement().

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

    {
        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:

RecursiveTreeIterator::setPrefixPart ( part,
value 
)

Set prefix part as used in getPrefix() and stored in $prefix.

Parameters:
$partany PREFIX_* const.
$valuenew prefix string for specified part.
Exceptions:
OutOfRangeExceptionif 0 > $part or $part > 5.

Definition at line 60 of file recursivetreeiterator.inc.

    {
        if (0 > $part || $part > 5) {
            throw new OutOfRangeException();
        }
        $this->prefix[$part] = (string)$value;
    }
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().

    {
        $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:


Member Data Documentation

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

Definition at line 39 of file recursivetreeiterator.inc.

RecursiveTreeIterator::$rit_flags [private]

Definition at line 25 of file recursivetreeiterator.inc.

Referenced by __construct().

Definition at line 22 of file recursivetreeiterator.inc.

Definition at line 23 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.

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.

Prefix used if $level == depth and hasNext($level) == true.

Definition at line 48 of file recursivetreeiterator.inc.

Prefix used if $level == depth and hasNext($level) == false.

Definition at line 50 of file recursivetreeiterator.inc.

Prefix used to start elements.

Definition at line 42 of file recursivetreeiterator.inc.

Prefix used if $level < depth and hasNext($level) == true.

Definition at line 44 of file recursivetreeiterator.inc.

Prefix used if $level < depth and hasNext($level) == false.

Definition at line 46 of file recursivetreeiterator.inc.

Prefix used right in front of the current element.

Definition at line 52 of file recursivetreeiterator.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: