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
显示文件 Open project: puli/repository Class Usage Examples

Protected Properties

Property Type Description
$mode integer
$resources Puli\Repository\Api\Resource\PuliResource[]

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.

current() public method

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

public getCurrentResource ( )

hasChildren() public method

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

key() public method

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

next() public method

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

rewind() public method

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

valid() public method

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

Property Details

$mode protected_oe property

protected int $mode
return integer

$resources protected_oe property

protected PuliResource[],Puli\Repository\Api\Resource $resources
return Puli\Repository\Api\Resource\PuliResource[]