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

List of all members.

Public Member Functions

 __call ($func, $params)
 __construct ()
 append (Iterator $it)
 current ()
 getInnerIterator ()
 key ()
 next ()
 rewind ()
 valid ()

Private Attributes

 $iterators

Detailed Description

Iterator that iterates over several iterators one after the other.

Author:
Marcus Boerger
Version:
1.0
Since:
PHP 5.1

Definition at line 18 of file appenditerator.inc.


Constructor & Destructor Documentation

AppendIterator::__construct ( )

Construct an empty AppendIterator.

Definition at line 25 of file appenditerator.inc.

    {
        $this->iterators = new ArrayIterator();
    }

Member Function Documentation

AppendIterator::__call ( func,
params 
)

Aggregates the inner iterator.

Definition at line 116 of file appenditerator.inc.

References getInnerIterator().

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

Here is the call graph for this function:

AppendIterator::append ( Iterator it)

Append an Iterator.

Parameters:
$itIterator to append

If the current state is invalid but the appended iterator is valid the AppendIterator itself becomes valid. However there will be no call to $it->rewind(). Also if the current state is invalid the inner ArrayIterator will be rewound und forwarded to the appended element.

Definition at line 38 of file appenditerator.inc.

    {
        $this->iterators->append($it);
    }
AppendIterator::current ( )
Returns:
the current value if it is valid or NULL

Implements Iterator.

Definition at line 71 of file appenditerator.inc.

References getInnerIterator().

    {
        /* Using $this->valid() would be exactly the same; it would omit
         * the access to a non valid element in the inner iterator. Since
         * the user didn't respect the valid() return value false this
         * must be intended hence we go on. */
        return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL;
    }

Here is the call graph for this function:

AppendIterator::getInnerIterator ( )
Returns:
the current inner Iterator

Implements OuterIterator.

Definition at line 45 of file appenditerator.inc.

Referenced by __call(), current(), key(), next(), rewind(), and valid().

    {
        return $this->iterators->current();
    }
AppendIterator::key ( )
Returns:
the current key if it is valid or NULL

Implements Iterator.

Definition at line 82 of file appenditerator.inc.

References getInnerIterator().

    {
        return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL;
    }

Here is the call graph for this function:

AppendIterator::next ( )

Move to the next element.

If this means to another Iterator that rewind that Iterator.

Returns:
void

Implements Iterator.

Definition at line 91 of file appenditerator.inc.

References getInnerIterator(), and valid().

    {
        if (!$this->iterators->valid())
        {
            return; /* done all */
        }
        $this->getInnerIterator()->next();
        if ($this->getInnerIterator()->valid())
        {
            return; /* found valid element in current inner iterator */
        }
        $this->iterators->next();
        while ($this->iterators->valid())
        {
            $this->getInnerIterator()->rewind();
            if ($this->getInnerIterator()->valid())
            {
                return; /* found element as first elemet in another iterator */
            }
            $this->iterators->next();
        }
    }

Here is the call graph for this function:

AppendIterator::rewind ( )

Rewind to the first element of the first inner Iterator.

Returns:
void

Implements Iterator.

Definition at line 53 of file appenditerator.inc.

References getInnerIterator().

    {
        $this->iterators->rewind();
        if ($this->iterators->valid())
        {
            $this->getInnerIterator()->rewind();
        }
    }

Here is the call graph for this function:

AppendIterator::valid ( )
Returns:
whether the current element is valid

Implements Iterator.

Definition at line 64 of file appenditerator.inc.

References getInnerIterator().

Referenced by next().

    {
        return $this->iterators->valid() && $this->getInnerIterator()->valid();
    }

Here is the call graph for this function:


Member Data Documentation

AppendIterator::$iterators [private]

array of inner iterators

Definition at line 21 of file appenditerator.inc.


The documentation for this class was generated from the following file: