2017 © Pedro Peláez
 

library generic-collections

Library to mimics generic collections

image

eclipxe/generic-collections

Library to mimics generic collections

  • Wednesday, March 22, 2017
  • by eclipxe
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

eclipxe/generic-collections

![Source Code][badge-source] Latest Version ![Software License][badge-license] [Build Status][build] ![Scrutinizer][badge-quality] ![Coverage Status][badge-coverage] Total Downloads SensioLabsInsight, (*1)

Generic Collections PHP Library is a PHP 5.6+ that mimics the Java Collections Framework., (*2)

As PHP does not have Generics this library will always implements type checks. Don't worry, anyways you can always use the mixed type, (*3)

For concrete classes uses a constructor approach:, (*4)

// collection = new Collection<Foo>();
$collection = new Collection(Foo::class);

For your own classes you could extend the abstract class and implement the appropiated type methods, by example:, (*5)

class Foos extends Collection
{
    public function __construct(array $elements)
    {
        parent::__construct(Foo::class, $elements);
    }
}

Installation

The preferred method of installation is via Packagist and Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:, (*6)

composer require eclipxe/generic-collections

List of classes

Basic classes:, (*7)

  • [x] Collection: A collection represents a group of elements of the same type.
  • [x] Set: A collection that only allows unique elements
  • [x] Queue: Collection for holding elements (FIFO)
  • [x] Deque: Double Ended Queue

Classes that implement \ArrayAccess, (*8)

  • [x] Map: A mapping from keys to values.
  • [ ] List: A collection that can be accessed by their integer index and search elements on the list.

Additional classes:, (*9)

  • [x] Stack: Collection for holding elements (LIFO)
  • [x] ~~Shape~~TypedStruct: Structure with typed values (also with \ArrayAccess)

All classes have these additional options:, (*10)

  • allow null elements/values
  • allow only unique elements/values
  • comparison equal (make equality comparisons between members instead of identical comparisons)

About

This library is inspired by the Java Collections Framework and PHP ramsey/collection library., (*11)

I see significant changes with ramsey's package, as I didn't want to introduce heavy changes to his API I decide to create my own approach., (*12)

I had also take a deep search on Packagist but couldn't find a library that ensure type checking on members., (*13)

Yes, my mistake, the repository username is eclipxe13/ and the packagist name is eclipxe/., (*14)

Compatibility

This class will be compatible according to PHP Supported versions, Security Support. This means that it will offer compatibility with PHP 5.6+ until 2018-12-31., (*15)

The support for version 5.5+ is not included since this PHP version will end 2016-06-10 and that is lower than the release of first version of this library., (*16)

Not taking particular efforts to make this library compatible with hhvm, hhvm have Generics support included and also has a collection library. I have seen differences on how hack language implement traits (like the ability to use abstracts methods) that are not compatible. Also I've seen a problem on hhvm 3.6.6 (the one is using Travis CI)implementation of SplDoubleLinkedList that are not present on version 3.12.1., (*17)

Documentation and examples

WIP. Be patient please., (*18)

Contributing

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look in the TODO and CHANGELOG files., (*19)

The eclipxe/generic-collections library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information., (*20)

The Versions

22/03 2017