2017 © Pedro Peláez
 

library collection

Collection type for PHP

image

phpextra/collection

Collection type for PHP

  • Wednesday, May 20, 2015
  • by jkobus
  • Repository
  • 2 Watchers
  • 2 Stars
  • 5,549 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 3 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

Collection (PHPExtra\Type\Collection)

Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality Code Coverage GitTip, (*1)

Usage

Collection solve few things by implementing following interfaces: \Countable, \ArrayAccess, \Iterator, and \SortableInterface. This gives you an ability to count() collection, use a foreach on it, access it like an array $a[1] and sort its contents $a->sort($sorter). Apart from regular collections there are also LazyCollection's that allow you to specify a closure that will initialize collection contents only if it's needed., (*2)

Create your first collection:, (*3)

$collection = new Collection();

$collection->add('item1');
$collection->add('item2');
$collection->add('item3');

Use it:, (*4)

echo count($collection); // returns 3
echo $collection[0]; // returns "item1"
echo $collection->slice(1, 2); // returns Collection with a length of 2 containing item2 and item3.
echo $collection->filter(function($element, $offset){ return $offset % 2 == 0; }); // returns sub-collection with all elements with even offset number
$collection->sort(SorterInterface $sorter); // sorts collection

Lazy collection example:, (*5)

$lazy = new LazyCollection(function(){
    return new Collection(array(1, 2, 3));
});

echo $lazy[2]; // initializes the closure and returns "3"

Installation (Composer)

{
    "require": {
        "phpextra/collection":"~1.0"
    }
}

Changelog

No releases yet

Contributing

All code contributions must go through a pull request. Fork the project, create a feature branch, and send me a pull request. To ensure a consistent code base, you should make sure the code follows the coding standards. If you would like to help take a look at the list of issues., (*6)

Requirements

See composer.json for a full list of dependencies.

Authors

Jacek Kobus - <kobus.jacek@gmail.com>

License information

See the file LICENSE.txt for copying permission.on.

The Versions

20/05 2015

dev-master

9999999-dev https://github.com/phpextra/collection

Collection type for PHP

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Jacek Kobus

collection

02/04 2015

dev-collection-4

dev-collection-4 https://github.com/phpextra/collection

Collection type for PHP

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

by Jacek Kobus

collection