CachingIterator
class CachingIterator extends IteratorIterator implements ArrayAccess, Countable, Stringable (View source)
This object supports cached iteration over another iterator.
Constants
CALL_TOSTRING |
String conversion flag (mutually exclusive): Uses the current element for the iterator's string conversion. This converts the current element to a string only once, regardless of whether it is needed or not. |
TOSTRING_USE_KEY |
String conversion flag (mutually exclusive). Uses the current key for the iterator's string conversion. |
TOSTRING_USE_CURRENT |
String conversion flag (mutually exclusive). Uses the current element for the iterator's string conversion. This converts the current element to a string only when (and every time) it is needed. |
TOSTRING_USE_INNER |
String conversion flag (mutually exclusive). Forwards the string conversion to the inner iterator. This converts the inner iterator to a string only once, regardless of whether it is needed or not. |
CATCH_GET_CHILD |
Ignore exceptions thrown in accessing children. Only used with {RecursiveCachingIterator}. |
FULL_CACHE |
Cache all read data. This is needed to use {CachingIterator and ArrayAccess and Countable methods. |
Methods
Constructs a new CachingIterator.
Returns the inner iterator
Rewind the iterator
Check whether the current element is valid
Return the key for the current element
Return the current element
Move the iterator forward
Check whether the inner iterator has a valid next element
Return the string representation of the current iteration based on the flag being used.
Get flags used
The setFlags purpose
Internal cache array index to retrieve.
Set an element on the internal cache array.
Remove an element from the internal cache array.
Return whether an element at the index exists on the internal cache array.
Retrieve the contents of the cache
The number of elements in the iterator
Details
__construct(Traversable $iterator, int $flags = self::CALL_TOSTRING)
Constructs a new CachingIterator.
Iterator|null
getInnerIterator()
Returns the inner iterator
void
rewind()
Rewind the iterator
bool
valid()
Check whether the current element is valid
mixed
key()
Return the key for the current element
mixed
current()
Return the current element
void
next()
Move the iterator forward
bool
hasNext()
Check whether the inner iterator has a valid next element
string
__toString()
Return the string representation of the current iteration based on the flag being used.
int
getFlags()
Get flags used
void
setFlags(int $flags)
The setFlags purpose
mixed
offsetGet(string $key)
Internal cache array index to retrieve.
void
offsetSet(string $key, TValue $value)
Set an element on the internal cache array.
void
offsetUnset(string $key)
Remove an element from the internal cache array.
bool
offsetExists(string $key)
Return whether an element at the index exists on the internal cache array.
array
getCache()
Retrieve the contents of the cache
int
count()
The number of elements in the iterator