PHP Class 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) {
...
}
ファイルを表示
Open project: puli/repository
Class Usage Examples
Protected Properties
Public Methods
Method |
Description |
|
__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. |
|
Method Details
__construct()
public method
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. |
Returns the current value of the iterator.
public current ( ) : Puli\Repository\Api\Resource\PuliResource | string |
return |
Puli\Repository\Api\Resource\PuliResource | string |
The current value as configured in
{@link __construct}. |
getChildren()
public method
Returns the iterator for the children of the current element.
public getChildren ( ) : static |
return |
static |
Returns an instance of this class for the children of
the current element. |
getCurrentResource()
public method
hasChildren()
public method
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.
Property Details
$mode protected_oe property
$resources protected_oe property
protected PuliResource[],Puli\Repository\Api\Resource $resources |
return |
Puli\Repository\Api\Resource\PuliResource[] |
|