PHP code example of shrikeh / collections

1. Go to this page and download the library: Download shrikeh/collections library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shrikeh / collections example snippets




namespace Shrikeh\Collection\Examples;

use IteratorIterator;
use Shrikeh\Collection\Examples\SomeObject;

/**
 * An immutable iterator that can only contain SomeObject objects.
 */
final class ImmutableSomeObjectCollection extends IteratorIterator
{
    use \Shrikeh\Collection\NamedConstructorsTrait;   # Give it named constructors
    use \Shrikeh\Collection\ImmutableCollectionTrait; # Give it read-only array access
    use \Shrikeh\Collection\ClosedOuterIteratorTrait; # Close off access to the inner iterator
    use \Shrikeh\Collection\OuterIteratorTrait;       # Give it all the standard read access methods
    use \Shrikeh\Collection\ObjectStorageTrait;       # Set inner storage to SplObjectStorage

    # Append method is called by ObjectStorageTrait during construction, so we
    # type hint the relevant class/interface we need...
    protected function append(SomeObject $object, $key)
    {
        $this->getStorage()->attach($object);
    }
}