class CachingIterator implements Iterator (View source)

Iterator for wrapping a Traversable and caching its results.

By caching results, this iterators allows a Traversable to be counted and rewound multiple times, even if the wrapped object does not natively support those operations (e.g. MongoDB\Driver\Cursor).

Methods

__construct(Traversable $iterator)

Initialize the iterator and stores the first item in the cache. This effectively rewinds the Traversable and the wrapping Generator, which will execute up to its first yield statement. Additionally, this mimics behavior of the SPL iterators and allows users to omit an explicit call to rewind() before using the other methods.

toArray()

No description

mixed
current()

No description

mixed
key()

No description

next()

No description

rewind()

No description

bool
valid()

No description

Details

__construct(Traversable $iterator)

Initialize the iterator and stores the first item in the cache. This effectively rewinds the Traversable and the wrapping Generator, which will execute up to its first yield statement. Additionally, this mimics behavior of the SPL iterators and allows users to omit an explicit call to rewind() before using the other methods.

Parameters

Traversable $iterator

toArray()

mixed current()

Return Value

mixed

See also

http://php.net/iterator.current

mixed key()

Return Value

mixed

See also

http://php.net/iterator.mixed

bool valid()

Return Value

bool

See also

http://php.net/iterator.valid