Download the PHP package star/collection without Composer

On this page you can find all versions of the php package star/collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package collection

collection

Master: Build Status

Develop: Build Status

Library that offer multiple implementations of collection.

Installation

To install the package using [composer] (https://getcomposer.org/), you just need to add the following lines to your composer.json file.

...
"require": {
    "star/collection": "~1.2"
}
...

Supported collection

Enumeration

Wrap an immutable array of values in an object. Ensuring that any value passed to the enumeration is supported by the instance.

$enumeration = new Enumeration(array(1,2,3));
$enumeration->getSelected(); // returns null
$enumeration->select(2);
$enumeration->getSelected(); // returns 2
$enumeration->select('invalid'); // Throw Exception

Typed Collection

Wraps a collection of a specific kind of object (class or interface). If a value not supported by the collection is given, the collection throws exceptions.

Basic usage

$collection = new TypedCollection('\stdClass');
$collection->add(2); // Throw exception
$collection->add(new \stdClass()); // works

$collection = new TypedCollection('\Countable');
$collection->add(2); // Throw exception
$collection->add(new ClassThatImplementsCountable()); // works

Advanced usage

Using composition

Lets say that you want a Car collection, you could just define it using the basic usage, but it would lead to code duplication. So a good practice would be to define a new class named CarCollection, and use composition instead of inheritance, and declare it like this:

class CarCollection
{
    private $collection;

    public function __construct()
    {
        $this->collection = new TypedCollection('tests\Star\Component\Collection\Example\Car');
    }
}

Declaring your collection like this will enable you to encapsulate logic relevant to the car collection at one place, instead of risking to expose the inner implementation to the outside world. That way, you can control what methods are available and avoid duplication.

Using this example, adding a Car to the collection would be easy by implementing the addCar method.

class CarCollection
{
    ...
    public function addCar(Car $car)
    {
        $this->collection->add($car);
    }
    ...
}

And, if you want to filter all the cars based on their color, you can internally use it like this:

class CarCollection
{
    ...
    public function findAllCarWithColor(Color $color)
    {
        $closure = function(Car $car) use ($color) {
            return $car->getColor() == $color;
        };

        return $this->collection->filter($closure)->toArray();
    }
    ...
}

The same could also be done for finding cars based on their name:

class CarCollection
{
    ...
    public function findAllWithName($name)
    {
        $expression = Criteria::expr()->eq('name', $name);
        $criteria = new Criteria($expression);

        return $this->collection->matching($criteria)->toArray();
    }
    ...
}

From now on, your collection is re-usable, and testable at one place, while avoiding the pitfalls of inheritance.

Using Inheritance

class PassengerCollection extends TypedCollection
{
    ...
    public function findAllWithName($name)
    {
        $expression = Criteria::expr()->eq('name', $name);
        $criteria = new Criteria($expression);

        return $this->matching($criteria)->toArray();
    }
    ...
}

Using Doctrine

This class can be used in conjunction with doctrine/dbal as an added functionality, but you need to make sure that the following steps are respected.


All versions of collection with dependencies

PHP Build Version
Package Version
Requires doctrine/collections Version ~1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package star/collection contains the following files

Loading the files please wait ....