eclipxe/generic-collections

Library to mimics generic collections

v0.3.0 2017-03-22 00:54 UTC

This package is auto-updated.

Last update: 2024-11-09 18:56:43 UTC


README

Source Code Latest Version Software License Build Status Scrutinizer Coverage Status Total Downloads SensioLabsInsight

Generic Collections PHP Library is a PHP 5.6+ that mimics the Java Collections Framework.

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

For concrete classes uses a constructor approach:

// 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:

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:

composer require eclipxe/generic-collections

List of classes

Basic classes:

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

Classes that implement \ArrayAccess

  • 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:

  • Stack: Collection for holding elements (LIFO)
  • ShapeTypedStruct: Structure with typed values (also with \ArrayAccess)

All classes have these additional options:

  • 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.

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.

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

Yes, my mistake, the repository username is eclipxe13/ and the packagist name is eclipxe/.

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.

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.

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.

Documentation and examples

WIP. Be patient please.

Contributing

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

Copyright and License

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.