PHP library to create custom collections

PHP library to create custom collections


PHP library to create custom collections.


Define a custom collection, extending library’s abstract collection and defining the item and offset types


class MyCustomCollection extends TandiljuanCollectionAbstractCollection
     * {@inheritdoc}
    protected $itemType = 'DateTime';

     * {@inheritdoc}
    protected $offsetType = 'integer';

Create a collection that only will allow the item and offset types you have defined


$collection = new MyCustomCollection();

try {
    $collection = 'error';
} catch (TandiljuanCollectionExceptionInvalidItemType $e) {
    echo "Invalid item typen";

try {
    $collection['a'] = new DateTime();
} catch (TandiljuanCollectionExceptionInvalidOffsetType $e) {
    echo "Invalid offset typen";

$collection = new DateTime('2001-01-01 01:01:01');
$collection = new DateTime('2002-02-02 02:02:02');
$collection = new DateTime('2003-03-03 03:03:03');

Require parameters to be of MyCustomCollection using type declarations


function printItems(MyCustomCollection $parameter)
    foreach ($parameter as $item) {
        echo $item->format('r')."n";


// The output will be
// Mon, 01 Jan 2001 01:01:01 +0000
// Sat, 02 Feb 2002 02:02:02 +0000
// Mon, 03 Mar 2003 03:03:03 +0000


Contributions must follow Symfony Coding Standards.

It’s encouraged to read the following documentation:

The run bash script is a wrapper of a php docker container. It will bootstrap the container and run a given command inside of it. The container should have all needed tools for development. Please, let know the project maintainer if something is missing.

To add new packages in the composer.json file, use composer require

./run composer require [--dev] [vendor/package:version]

To install packages defined in the composer.json file, use composer install

./run composer install

To check PHP code against coding standards, use php-cs-fixer

# Check if a file needs to be fixed
./run php-cs-fixer fix --dry-run --diff path/to/file.php
# Fix a file
./run php-cs-fixer fix path/to/file.php

To run PHP REPL interactive shell, use php or psysh

# Using PHP
./run php -a
# Using psysh
./run psysh


Bootstrap Codeception test environment. This must be done only once.

$ # Bootstrap codeception without the standard suites
$ ./run codecept bootstrap --empty --namespace 'TandiljuanCollectionTests'

Create a codeception test suit. This must be done only once per suit.

$ # Create `unit` suit (for unit testing)
$ ./run codecept generate:suite unit

Create a Cest class under a given suit. Can create as many Cest classes as needed.

$ # Create a new cest `Dummy` under the `unit` suit
$ ./run codecept generate:cest unit Dummy

After writing the tests, can execute them using the run command

$ ./run codecept run


Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *