SPL-StandardPHPLibrary
Public Member Functions | Private Attributes | List of all members
AppendIterator Class Reference
Inheritance diagram for AppendIterator:
Inheritance graph
Collaboration diagram for AppendIterator:
Collaboration graph

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.

26  {
27  $this->iterators = new ArrayIterator();
28  }
An Array iterator.
Definition: spl.php:741

Member Function Documentation

AppendIterator::__call (   $func,
  $params 
)

Aggregates the inner iterator.

Definition at line 116 of file appenditerator.inc.

References getInnerIterator().

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

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.

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

Implements Iterator.

Definition at line 71 of file appenditerator.inc.

References getInnerIterator().

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

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

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

Implements Iterator.

Definition at line 82 of file appenditerator.inc.

References getInnerIterator().

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

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

92  {
93  if (!$this->iterators->valid())
94  {
95  return; /* done all */
96  }
97  $this->getInnerIterator()->next();
98  if ($this->getInnerIterator()->valid())
99  {
100  return; /* found valid element in current inner iterator */
101  }
102  $this->iterators->next();
103  while ($this->iterators->valid())
104  {
105  $this->getInnerIterator()->rewind();
106  if ($this->getInnerIterator()->valid())
107  {
108  return; /* found element as first elemet in another iterator */
109  }
110  $this->iterators->next();
111  }
112  }

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

54  {
55  $this->iterators->rewind();
56  if ($this->iterators->valid())
57  {
58  $this->getInnerIterator()->rewind();
59  }
60  }

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

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

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: