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) { ... }
Since: 1.0
Author: Bernhard Schussek ([email protected])
Inheritance: implements RecursiveResourceIterator
Afficher le fichier Open project: puli/repository Class Usage Examples

Protected Properties

Свойство Type Description
$mode integer
$resources Puli\Repository\Api\Resource\PuliResource[]

Méthodes publiques

Méthode 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 méthode

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() public méthode

Returns the current value of the iterator.
public current ( ) : Puli\Repository\Api\Resource\PuliResource | string
Résultat Puli\Repository\Api\Resource\PuliResource | string The current value as configured in {@link __construct}.

getChildren() public méthode

Returns the iterator for the children of the current element.
public getChildren ( ) : static
Résultat static Returns an instance of this class for the children of the current element.

getCurrentResource() public méthode

public getCurrentResource ( )

hasChildren() public méthode

Returns whether the iterator can be applied recursively over the current element.
public hasChildren ( ) : boolean
Résultat boolean Whether the current element can be iterated recursively.

key() public méthode

Returns the current key of the iterator.
public key ( ) : integer | string | null
Résultat integer | string | null The current key as configured in {@link __construct} or `null` if the cursor is behind the last element.

next() public méthode

Advances the iterator to the next position.
public next ( )

rewind() public méthode

Rewinds the iterator to the first entry.
public rewind ( )

valid() public méthode

Returns whether the iterator points to a valid key.
public valid ( ) : boolean
Résultat boolean Whether the iterator position is valid.

Property Details

$mode protected_oe property

protected int $mode
Résultat integer

$resources protected_oe property

protected PuliResource[],Puli\Repository\Api\Resource $resources
Résultat Puli\Repository\Api\Resource\PuliResource[]