SPL-StandardPHPLibrary
Public Member Functions | Public Attributes | Protected Attributes
RecursiveCompareDualIterator Class Reference
Inheritance diagram for RecursiveCompareDualIterator:
Inheritance graph
[legend]
Collaboration diagram for RecursiveCompareDualIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Protected Attributes

 $equal = false

Detailed Description

Recursive comparison iterator for a RecursiveDualIterator.

Author:
Marcus Boerger
Version:
1.0

Definition at line 17 of file recursivecomparedualiterator.inc.


Constructor & Destructor Documentation

RecursiveCompareDualIterator::__construct ( RecursiveDualIterator it,
mode = self::LEAVES_ONLY,
flags = 0 
)

Construct from RecursiveDualIterator.

Parameters:
$itRecursiveDualIterator
$modeshould be LEAVES_ONLY
$flagsshould be 0

Definition at line 30 of file recursivecomparedualiterator.inc.


Member Function Documentation

RecursiveCompareDualIterator::areEqual ( )
Returns:
whether both inner iterators are valid and have equal current and key values or both are non valid.

Definition at line 63 of file recursivecomparedualiterator.inc.

References RecursiveIteratorIterator\getInnerIterator().

    {
        return $this->equal && $this->getInnerIterator()->areEqual();
    }

Here is the call graph for this function:

RecursiveCompareDualIterator::areIdentical ( )
Returns:
whether both inner iterators are valid and have identical current and key values or both are non valid.

Definition at line 55 of file recursivecomparedualiterator.inc.

References RecursiveIteratorIterator\getInnerIterator().

    {
        return $this->equal && $this->getInnerIterator()->areIdentical();
    }

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

Implements Iterator.

Reimplemented in RecursiveTreeIterator, and DirectoryTreeIterator.

Definition at line 99 of file recursiveiteratoriterator.inc.

References $it.

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

Calculate $equal.

See also:
$equal

Reimplemented from RecursiveIteratorIterator.

Definition at line 46 of file recursivecomparedualiterator.inc.

References RecursiveIteratorIterator\getInnerIterator().

    {
        $this->equal &= !$this->getInnerIterator()->getLHS()->valid()
                     && !$this->getInnerIterator()->getRHS()->valid();
    }

Here is the call graph for this function:

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

Definition at line 177 of file recursiveiteratoriterator.inc.

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

    {
        return $this->level;
    }
RecursiveIteratorIterator::getInnerIterator ( ) [inherited]
Returns:
The inner iterator

Implements OuterIterator.

Definition at line 170 of file recursiveiteratoriterator.inc.

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

    {
        return $this->it;
    }
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(), RecursiveTreeIterator\__call(), DirectoryTreeIterator\current(), and RecursiveTreeIterator\getPrefix().

    {
        if (is_null($level)) {
            $level = $this->count;
        }
        return @$this->ait[$level];
    }
RecursiveIteratorIterator::key ( ) [inherited]
Returns:
current key

Implements Iterator.

Reimplemented in RecursiveTreeIterator.

Definition at line 91 of file recursiveiteratoriterator.inc.

References $it.

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

    {
    }
RecursiveCompareDualIterator::rewind ( )

Rewind iteration andcomparison process.

Starting with $equal = true.

Reimplemented from RecursiveIteratorIterator.

Definition at line 37 of file recursivecomparedualiterator.inc.

    {
        $this->equal = true;
        parent::rewind();
    }
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

RecursiveCompareDualIterator::$equal = false [protected]

Used to keep end of recursion equality.

That is en leaving a nesting level we need to check whether both child iterators are at their end.

Definition at line 22 of file recursivecomparedualiterator.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.

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: