|
SPL-StandardPHPLibrary
|


Public Member Functions | |
| __construct ($flags=self::MIT_NEED_ALL|self::MIT_KEYS_NUMERIC) | |
| attachIterator (Iterator $iter, $inf=NULL) | |
| containsIterator (Iterator $iter) | |
| countIterators () | |
| current () | |
| detachIterator (Iterator $iter) | |
| getFlags () | |
| key () | |
| next () | |
| rewind () | |
| setFlags ($flags) | |
| valid () | |
Public Attributes | |
| const | MIT_KEYS_ASSOC = 2 |
| const | MIT_KEYS_NUMERIC = 0 |
| const | MIT_NEED_ALL = 1 |
| const | MIT_NEED_ANY = 0 |
Private Attributes | |
| $flags | |
| $iterators | |
Iterator that iterates over several iterators one after the other.
Definition at line 19 of file multipleiterator.inc.
| MultipleIterator::__construct | ( | $ | flags = self::MIT_NEED_ALL|self::MIT_KEYS_NUMERIC | ) |
Construct a new empty MultipleIterator.
| flags | MIT_* flags |
Definition at line 42 of file multipleiterator.inc.
References $flags.
{
$this->iterators = new SplObjectStorage();
$this->flags = $flags;
}
| MultipleIterator::attachIterator | ( | Iterator $ | iter, |
| $ | inf = NULL |
||
| ) |
| $iter | new Iterator to attach. |
| $inf | associative info forIteraotr, must be NULL, integer or string |
| IllegalValueException | if a inf is none of NULL, integer or string |
| IllegalValueException | if a inf is already an associated info |
Definition at line 66 of file multipleiterator.inc.
{
if (!is_null($inf))
{
if (!is_int($inf) && !is_string($inf))
{
throw new IllegalValueException('Inf must be NULL, integer or string');
}
foreach($this->iterators as $iter)
{
if ($inf == $this->iterators->getInfo())
{
throw new IllegalValueException('Key duplication error');
}
}
}
$this->iterators->attach($iter, $inf);
}
| MultipleIterator::containsIterator | ( | Iterator $ | iter | ) |
| $iter | Iterator to check |
Definition at line 95 of file multipleiterator.inc.
{
return $this->iterator->contains($iter);
}
| MultipleIterator::countIterators | ( | ) |
Definition at line 101 of file multipleiterator.inc.
{
return $this->iterators->count();
}
| MultipleIterator::current | ( | ) |
| RuntimeException | if mode MIT_NEED_ALL is set and at least one attached Iterator is not valid(). |
| IllegalValueException | if a key is NULL and MIT_KEYS_ASSOC is set. |
Implements Iterator.
Definition at line 157 of file multipleiterator.inc.
References $it.
{
if (!sizeof($this->iterators))
{
return false;
}
$retval = array();
foreach($this->iterators as $iter)
{
if ($it->valid())
{
if ($this->flags & self::MIT_KEYS_ASSOC)
{
$key = $this->iterators->getInfo();
if (is_null($key))
{
throw new IllegalValueException('Sub-Iterator is associated with NULL');
}
$retval[$key] = $iter->current();
}
else
{
$retval[] = $iter->current();
}
}
else if ($this->flags & self::MIT_NEED_ALL)
{
throw new RuntimeException('Called current() with non valid sub iterator');
}
else
{
$retval[] = NULL;
}
}
return $retval;
}
| MultipleIterator::detachIterator | ( | Iterator $ | iter | ) |
| $iter | attached Iterator that should be detached. |
Definition at line 87 of file multipleiterator.inc.
{
$this->iterators->detach($iter);
}
| MultipleIterator::getFlags | ( | ) |
Definition at line 49 of file multipleiterator.inc.
{
return $this->flags;
}
| MultipleIterator::key | ( | ) |
| LogicException | if mode MIT_NEED_ALL is set and at least one attached Iterator is not valid(). |
Implements Iterator.
Definition at line 199 of file multipleiterator.inc.
References $it.
{
if (!sizeof($this->iterators))
{
return false;
}
$retval = array();
foreach($this->iterators as $iter)
{
if ($it->valid())
{
$retval[] = $iter->key();
}
else if ($this->flags & self::MIT_NEED_ALL)
{
throw new LogicException('Called key() with non valid sub iterator');
}
else
{
$retval[] = NULL;
}
}
return $retval;
}
| MultipleIterator::next | ( | ) |
Move all attached Iterator instances forward.
That is invoke their next() method regardless of their state.
Implements Iterator.
Definition at line 143 of file multipleiterator.inc.
{
foreach($this->iterators as $iter)
{
$iter->next();
}
}
| MultipleIterator::rewind | ( | ) |
Rewind all attached Iterator instances.
Implements Iterator.
Definition at line 107 of file multipleiterator.inc.
{
foreach($this->iterators as $iter)
{
$iter->rewind();
}
}
| MultipleIterator::setFlags | ( | $ | flags | ) |
| $flags | new flags. |
Definition at line 55 of file multipleiterator.inc.
References $flags.
{
$this->flags = $flags;
}
| MultipleIterator::valid | ( | ) |
Implements Iterator.
Definition at line 122 of file multipleiterator.inc.
{
if (!sizeof($this->iterators)) {
return false;
}
// The following code is an optimized version that executes as few
// valid() calls as necessary and that only checks the flags once.
$expect = $this->flags & self::MIT_NEED_ALL ? true : false;
foreach($this->iterators as $iter)
{
if ($expect != $iter->valid())
{
return !$expect;
}
}
return $expect;
}
MultipleIterator::$flags [private] |
Flags: const MIT_*.
Definition at line 25 of file multipleiterator.inc.
Referenced by __construct(), and setFlags().
MultipleIterator::$iterators [private] |
Inner Iterators.
Definition at line 22 of file multipleiterator.inc.
| const MultipleIterator::MIT_KEYS_ASSOC = 2 |
keys are created from sub iterators associated infromation
Definition at line 37 of file multipleiterator.inc.
| const MultipleIterator::MIT_KEYS_NUMERIC = 0 |
keys are created from sub iterators position
Definition at line 34 of file multipleiterator.inc.
| const MultipleIterator::MIT_NEED_ALL = 1 |
require all sub iterators to be valid in iteration
Definition at line 31 of file multipleiterator.inc.
| const MultipleIterator::MIT_NEED_ANY = 0 |
do not require all sub iterators to be valid in iteration
Definition at line 28 of file multipleiterator.inc.
1.7.5.1