PHP Класс Puli\Repository\Resource\Iterator\ResourceCollectionIterator
Use the iterator if you want to iterate a resource collection. You can
configure what the iterator should return as keys and values:
php
$iterator = new ResourceCollectionIterator(
$collection,
ResourceCollectionIterator::KEY_AS_PATH | ResourceCollectionIterator::CURRENT_AS_RESOURCE
);
foreach ($iterator as $path => $resource) {
...
}
If you want to iterate the collection recursively, wrap it in a
{@link RecursiveResourceIteratorIterator}:
php
$iterator = new RecursiveResourceIteratorIterator(
new ResourceCollectionIterator(
$collection,
ResourceCollectionIterator::KEY_AS_PATH | ResourceCollectionIterator::CURRENT_AS_RESOURCE
),
RecursiveResourceIteratorIterator::SELF_FIRST
);
foreach ($iterator as $path => $resource) {
...
}
Показать файл
Открыть проект
Примеры использования класса
Защищенные свойства (Protected)
Открытые методы
Метод |
Описание |
|
__construct ( Puli\Repository\Api\ResourceCollection $resources, integer | null $mode = null ) |
Creates a new iterator. |
|
current ( ) : Puli\Repository\Api\Resource\PuliResource | string |
Returns the current value of the iterator. |
|
getChildren ( ) : static |
Returns the iterator for the children of the current element. |
|
getCurrentResource ( ) |
|
|
hasChildren ( ) : boolean |
Returns whether the iterator can be applied recursively over the
current element. |
|
key ( ) : integer | string | null |
Returns the current key of the iterator. |
|
next ( ) |
Advances the iterator to the next position. |
|
rewind ( ) |
Rewinds the iterator to the first entry. |
|
valid ( ) : boolean |
Returns whether the iterator points to a valid key. |
|
Описание методов
__construct()
публичный Метод
The following constants can be used to configure the values returned by
the iterator:
* {@link CURRENT_AS_RESOURCE}: The {@link PuliResource} objects are
returned as values;
* {@link CURRENT_AS_PATH}: The resource paths are returned as values;
* {@link CURRENT_AS_NAME}: The resource names are returned as values.
The following constants can be used to configure the keys returned by
the iterator:
* {@link KEY_AS_CURSOR}: The collection keys are returned as keys;
* {@link KEY_AS_PATH}: The resource paths are returned as keys.
By default, the mode KEY_AS_PATH | CURRENT_AS_RESOURCE is used.
public __construct ( Puli\Repository\Api\ResourceCollection $resources, integer | null $mode = null ) |
$resources |
Puli\Repository\Api\ResourceCollection |
The resources to iterate. |
$mode |
integer | null |
A bitwise combination of the mode
constants. |
current()
публичный Метод
Returns the current value of the iterator.
public current ( ) : Puli\Repository\Api\Resource\PuliResource | string |
Результат |
Puli\Repository\Api\Resource\PuliResource | string |
The current value as configured in
{@link __construct}. |
getChildren()
публичный Метод
Returns the iterator for the children of the current element.
public getChildren ( ) : static |
Результат |
static |
Returns an instance of this class for the children of
the current element. |
getCurrentResource()
публичный Метод
hasChildren()
публичный Метод
Returns whether the iterator can be applied recursively over the
current element.
Returns the current key of the iterator.
Advances the iterator to the next position.
Rewinds the iterator to the first entry.
Returns whether the iterator points to a valid key.
Описание свойств
$mode защищенное свойство
protected int $mode |
Результат |
integer |
|
$resources защищенное свойство
protected PuliResource[],Puli\Repository\Api\Resource $resources |
Результат |
Puli\Repository\Api\Resource\PuliResource[] |
|