2017 © Pedro PelĂĄez
 

library php-collection

A library for handling sets of data

image

fschaechter/php-collection

A library for handling sets of data

  • Friday, September 12, 2014
  • by DavidBadura
  • Repository
  • 15 Watchers
  • 0 Stars
  • 8 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

PHP-Collection

PHP-Collection is an easy to use library for handling sets of data with support for filtering, sorting and reducing the data sets., (*1)

The class Collection extends PHP's ArrayObject and so brings a little extra to the table., (*2)

Build Status, (*3)

Installation

You can just clone the repository and use it as you see fit or use Composer and handle the dependency management very efficiently., (*4)

Composer

Append the following line to the require-key of your composer.json file., (*5)

"fschaechter/php-collection": "~2"

Issues and bugs

You can report bugs, problems and other issues here. Every useful bit is very much appreciated., (*6)

Tutorial

First you need a some data and create a collection., (*7)

<?php
$data = array(
    "Apple",
    "Apple,"
    "Pear",
    "Been",
    "Pear",
    "Strawberry",
);
$collection = new \Collection\Collection($data);

Append some more data., (*8)

<?php
$collection->append("Been");
$collection[] = "Pear";

Now you can just iterate over the data., (*9)

<?php
echo sprinft(
    "We have %s items." . PHP_EOL,
    count($collection)
);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

It would be nice if the collection is sorted., (*10)

<?php
$comparator = new \Collection\Comparator\String();
$sorter = new \Collection\Sorter\Uasort($comparator);
$collection->sort($sorter);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

We don't like apples., (*11)

<?php
$filter = new \Collection\Filter\Unequal("Apple");
$collection = $collection->filter($filter);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

Let's distill the items., (*12)

<?php
$reducer = new \Collection\Reducer\Distinct();
$collection = $collection->reduce($reducer);

foreach ($collection as $item) {
    echo $item . PHP_EOL;
}

More examples

Take a look at the examples directory, there you will find three example of how to play with a collection., (*13)

  • Look at example_filter.php to see the filter system in action.
  • Look at example_reduce.php to see how a reducer melts away unwanted data.
  • Look at example_sort.php to see how you can sort a collection of objects.

Quality?

This library is developed under the principles of TDD. You can find all the tests within the tests directory. Check for yourself using PHPUnit., (*14)

$ bin/phpunit

Apache Ant is used for the complete build process. See build.xml, the file is based on the one you can find in PHPUnit's github.com repo., (*15)

$ ant

And Travis-CI makes sure its tested over and over again., (*16)

Tips and tricks

Enhance the PATH

All commands are installed to the bin directory by Composer. Add this directory to the environment path and there are easy accessible., (*17)

Here's an example for BASH, add the line to the ~/.bashrc., (*18)

PATH="./bin:$PATH"

Now it is very simple to run the unit tests., (*19)

$ phpunit

Instead of, (*20)

$ bin/phpunit

So much more productivity gained., (*21)

Why?

I come across a lot of data in form of list almost daily and i need an easy, testable and pragmatic way to extract information of these lists., (*22)

License

This library is licensed under the terms of the GNU General Public License v3., (*23)

Whats new?

2.3.1 Updated documention.

Added Travis CI status image. Updated documentation., (*24)

2.3.0 Exceptions and a new filter.

Added exception classes. Added a new filter for simple filtering of arrays., (*25)

2.2.0 Enhanced collection.

Added isEmpty() to Collection, so you can check if the collection is empty or has some elements., (*26)

2.1.0 Enhanced collection.

Added method getFirst() to Collection. This makes it easier to access the first element of the collection., (*27)

2.0.1 Fixed example.

There was a bug in examples/example_sort.php., (*28)

2.0.0 Refactored comparators.

The comparators moved from the namespace \Collection\Sorter\Comparator to \Collection\Comparator. This changed the API incompatibly with the prior version 1.0.0., (*29)

1.0.0 Started library.

This is the initial project., (*30)

The Versions

12/09 2014

dev-master

9999999-dev http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

12/09 2014

2.3.1

2.3.1.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

28/08 2014

2.3.0

2.3.0.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

28/08 2014

2.2.0

2.2.0.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

28/08 2014

2.1.0

2.1.0.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

28/08 2014

2.0.1

2.0.1.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

28/08 2014

2.0.0

2.0.0.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting

26/08 2014

1.0.0

1.0.0.0 http://github.com/fschaechter/php-collection

A library for handling sets of data

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.10
  • ext-xdebug >=2.1.0

 

The Development Requires

by Fabian SchÀchter

filter collection list sorting