2017 © Pedro Peláez
 

package collection

A flexible PHP Collection complete with custom Iterator.

image

halfpastfouram/collection

A flexible PHP Collection complete with custom Iterator.

  • Tuesday, February 20, 2018
  • by bobkruithof
  • Repository
  • 2 Watchers
  • 2 Stars
  • 1,350 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 28 % Grown

The README.md

Build Status Code Climate Test Coverage Downloads Latest Stable Version, (*1)

Mutable

A flexible PHP Mutable complete with custom Iterator, part of the halfpastfouram code library., (*2)

What can you do with a collection?

A collection is a tool you can use to have a certain level of control over the data you store inside it. Where you could use an array in most situations a collection provides a more flexible way to deal with your data., (*3)

It is particularly useful to extend this class if you need to perform actions on a list of items or objects when they are added, removed, replaced or otherwise modified., (*4)

Control over collections

You can traverse all collection types. To give you more flexibility, use the ArrayAccess class which provides direct array access as if you were talking to an array. This class also provides an iterator that can be used in loops or even manually., (*5)

Array access example

$collection = new Collection\ArrayAccess( [ 0, 1, 2, 3 ] );
$collection[] = 0;
$collection[5] = 12;

Traversing

foreach( $collection as $key => $value ) {
    var_dump( $key, $value );
}

Manual traversing (ArrayAccess only)

$iterator   = $collection->getIterator();

// Jump forward to next position
$iterator->next();
var_dump( $iterator->current() );

// Go back one position
$iterator->previous();
var_dump( $iterator->getKey(), $iterator->current() );

// Receive the list of keys in the dataset.
var_dump( $iterator->calculateKeyMap() );

Installation

Using composer

$ composer require halfpastfouram/collection

Development

This project uses composer, which should be installed on your system. Most Linux systems have composer available in their PHP packages. Alternatively you can download composer from getcomposer.org., (*6)

If you use the PhpStorm IDE then you can simply init composer through the IDE. However, full use requires the commandline. See PhpStorm help, search for composer., (*7)

To start development, do composer install from the project directory., (*8)

Remark Do not use composer update unless you changed the dependency requirements in composer.json. The difference is that composer install will use composer.lock read-only, while composer update will update your composer.lock file regardless of any change. As the composer.lock file is committed to the repo, other developers might conclude dependencies have changed, while they have not., (*9)

The Versions

20/02 2018

dev-master

9999999-dev http://github.com/halfpastfouram/collection

A flexible PHP Collection complete with custom Iterator.

  Sources   Download

AGPL 3.0 AGPL-3.0-or-later

The Requires

  • php >=5.6.0 || ^7.0

 

The Development Requires

by Bob Kruithof

php collection

18/12 2016

v1.0.0

1.0.0.0 http://github.com/halfpastfouram/collection

A flexible PHP Collection complete with custom Iterator.

  Sources   Download

AGPL 3.0

The Requires

  • php >=5.6.0 || ^7.0

 

The Development Requires

by Bob Kruithof

php collection