2017 © Pedro Peláez
 

library collection

Collection tools for developpers

image

digitick/collection

Collection tools for developpers

  • Monday, February 5, 2018
  • by digitick
  • Repository
  • 7 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Collection

Collection management classes, (*1)

Diagramme de classes

alt tag, (*2)

Usage

List collections

A list collection store a set of items in an ordered way., (*3)

Basic list

A list that accept any type of items., (*4)

$size = 4;
$list = new BaseList($size);
$list->set (0, "First item"); // Setter style
$list[1] = 123; // Array style


foreach ($list as $item) {
    echo $item;
}

Typed list

You can define a list which will only contains items of the class you want. The collection ensure type checking., (*5)

<?php

require __DIR__ . "/vendor/autoload.php";

// The class you want to be in your list collection
class MyItem {
    public $value;

    /**
     * MyItem constructor.
     * @param $value
     */
    public function __construct($value)
    {
        $this->value = $value;
    }

    /**
     * @return mixed
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param mixed $value
     * @return MyItem
     */
    public function setValue($value)
    {
        $this->value = $value;
        return $this;
    }

}

// Declare your list collection for class MyItem
class MyItemList extends \Digitick\Foundation\Collection\AbstractTypedList
{
    /**
     * @var string
     */
    protected static $CLASSORTYPENAME = "MyItem"; // Ensure that the list will only contains items of class MyItem
}

// You must give the size of your list
$myList = new MyItemList (3);

// You can access to your list like standard PHP array
$myList [0] = new MyItem(1);
$myList [1] = new MyItem(2);
$myList [2] = new MyItem(3);
// Except for this syntax : new values can not be pushed at the end of the list;
//$myList [] = new MyItem(3); // Throw exception

// You can iterate over your list with foreach syntax
/** @var MyItem $item */
foreach ($myList as $item) {
    echo "Item : " . $item->getValue() . "\n";
}

Integer list

Predefined typed list for integers., (*6)

$list = new IntList($size);
$list->set (0, 123); // Setter style
$list[1] = 123; // Array style
$list[2] = "foo"; // throw exception

String List

Predefined typed list for strings., (*7)

$names = new \Digitick\Foundation\Collection\StringList(2);
$names [0] = "Emilio Bradshaw";
$names [1] = "Dyler Runner";

Set collection

Unlike list collection, with a set collection elements are not ordered., (*8)

$lottery = new \Digitick\Foundation\Collection\IntScalarSet(10);
for ($i = 0; $i < 10; $i++) {
    $randomNumber = rand (1, 10);
    echo "Add $randomNumber\n";
    $lottery->add($randomNumber);
}

if ($lottery->contains(5)) {
    echo "Number 5 exists : WIN !";
} else {
    echo "Number 5 is elsewhere: LOOSE !";
}

Typed set

Like list collection a set can be constrains to a specific type / class., (*9)

class CustomType {

}

class CustomTypeSet extends \Digitick\Foundation\Collection\AbstractTypedObjectSet
{
    /**
     * @var string
     */
    protected static $CLASSORTYPENAME = 'CustomType';
}

$customSet = new CustomTypeSet();
$customSet->add (new CustomType());

The Versions

05/02 2018

dev-master

9999999-dev

Collection tools for developpers

  Sources   Download

Apache-2.0 Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini
by Alexandre Del Vecchio

14/12 2017

v1.1.2

1.1.2.0

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini
by Alexandre Del Vecchio

02/05 2017

v1.1.1

1.1.1.0

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini
by Alexandre Del Vecchio

24/01 2017

v1.1.0

1.1.0.0

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini

09/12 2016

dev-MiniDoc

dev-MiniDoc

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini

30/11 2016

v1.0.0

1.0.0.0

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini

09/11 2016

v0.1.0

0.1.0.0

Collection tools for developpers

  Sources   Download

Apache 2

The Requires

  • php >=5.4

 

The Development Requires

by Nicolas Natalini