A Collections library for PHP.

Overview

A Library of Collections for OO Programming

Build Status

While developing and helping others develop PHP applications I noticed the trend to use PHP's arrays in nearly every task. Arrays in PHP are useful but are overused because PHP doesn't have rich standard libraries for working with common data structures and algorithms. This library hopes to fill in that gap. Undoubtably, I've made mistakes in design and implementation; hopefully more community involvement can help identify and fix such mistakes.

Requirements

Patience

This project is unstable and subject to significant changes from release to release. Stability is not a goal during this phase of development. To be clear: you are using this project at your own risk. I highly value your experience using this library and am thankful for the early adopters, but I want to emphasize that this project is highly unstable.

PHP 5.4

This project requires PHP 5.4 because PHP 5.3 is at its End Of Life (EOL). As such the project makes use of Traits, the callable type and short array syntax. Depending on how long this project takes to mature it might require PHP 5.5 for generators and improved handling of non-scalar keys in foreach loops, or maybe PHP 5.6 for ... support.

You can also use HHVM. I won't let HHVM compatibility stop me from doing what I feel is right for this library, but hopefully we can maintain compatibility.

Roadmap

There is no official roadmap for this project. I intend to release version 1.0.0 when I am confident enough in the API that it is suitable for public use. Until then, minor versions will be tagged as they are deemed helpful. This project follows semantic versioning.

How can I help?

The best way to help is to use the library (again, at your own risk) and submit issues when you find them. Over 99% of the library has been executed in a unit test but the quality of some of these tests is poor; improved tests are definitely welcome.

Can you add X structure?

Maybe. Open an issue and I'll look into it.

Why not use the existing Standard PHP Library?

The Standard PHP Library (SPL) has many problems, some of which are documented in an unfinished RFC regarding the SPL. I won't go into full details here, but essentially the SPL is not providing the standardized data structures and algorithms that I feel the PHP community needs.

What's up with the name?

This project was originally aimed to fix the SPL; as such I had named it SPL. Eventually I realized that I would do better with a different name; I picked Ardent it describes how I feel about the need for this kind of library. Unfortunately another PHP project decided to use the name after I had already picked it.

Comments
  • Add priority queue.

    Add priority queue.

    SPL has priority queues, but they lack a key piece of functionality: the ability to decrease the key of a queue element. A fair number of uses of priority queues depend on this. One example is Djisktra's algorithm. This class is an implementation of a pairing heap, which has performance almost as good as that of a Fibonacci heap, but is considerably simpler to implement.

    This class has a few notable differences from the SPL implementations:

    • The queue exclusively accepts objects. The reason for this is that it uses SPLObjectStorage as a way to map inserted elements with their tree objects. An elegant method for relaxing this restriction would be a nice improvment.
    • It does not implement the Iterator interface. It can if there appears to be a need, but I struggle to see the reason for it. Therefore, I'm KISSing it until proven otherwise.
    • Arbitrary elements can be removed. With the pieces in place to reprioritize elements, it seemed an easy task to add what should be a useful ability.

    One issue with this pull that I'm not thrilled with, but count as "good enough for now" is the test. It does its job, but is ugly and could use improvements from someone who's better at writing tests.

    opened by mcordingley 23
  • Let Composer Handle Autoloading

    Let Composer Handle Autoloading

    I see that the library currently implements its own autoload function. Why not just use PSR-4 autoloading and let Composer handle this? It'll make it easier to alter this library while it is on its way to 1.0 and will make it simpler for others to contribute.

    If your concern is about performance, your current implementation is a class map. Running composer with the -o flag will generate a class map, instead of attempting to map namespaces to file system locations. Performance should be the same at that point and you'll have DRYer code, as you won't be repeating logic found elsewhere.

    opened by mcordingley 9
  • No last/first methods on sets

    No last/first methods on sets

    There is no last or first method (to retrieve the first or last item, of course) on the set classes. This seems like it'd be something useful to have (and is present in other implementations of sets).

    Feature Request 
    opened by daviddesberg 6
  • Filter and Sort arbitrary Collections

    Filter and Sort arbitrary Collections

    Is it possible to apply multiple filters on arbitrary Collections of this package? I just found a solution to apply a single filter (should be possible by using CallbackFilterIterator).

    And is there a preferred or standardised way to sort a collection of objects by a specific attribute?

    opened by inkrement 5
  • Is having main collection interfaces always extending IteratorAggregate the best option?

    Is having main collection interfaces always extending IteratorAggregate the best option?

    Couldn't be more convenient, sometimes, to implement Traversable using Iterator?

    interface Map extends \ArrayAccess, \Countable, Enumerable { ... } -> interface Map extends \ArrayAccess, \Countable, Collection { ... }

    opened by Wes0617 5
  • Filter Counter

    Filter Counter

    From https://github.com/morrisonlevi/Ardent/blob/master/src/Ardent/Iterator/FilteringIterator.php i notice the following code

    
        function count() {
            $i = 0;
            for ($this->rewind(); $this->valid(); $this->next()) {
                $i++;
            }
            return $i;
        }
    
    

    Why just just implement FilteringIterator::$counter has integer and just do basic increment and decrements ?

    opened by olekukonko 5
  • Method visibility

    Method visibility

    I've been looking though this library a bit and started wondering why most methods do not have an explicit visibility declared. Is there a reason for using function foo rather than public function foo?

    There are places where I am wondering if things are intentionally public or are just missing either private or protected. For instance HashMap::areEqual. This method does not make sense as part of this the public interface of this class. An anonymous function could be used in contains. Though perhaps it is done like this to allow overriding in derivatives of HashMap?

    opened by JeroenDeDauw 4
  • Run tests on travis

    Run tests on travis

    How about enabling testing with https://travis-ci.org/? :)

    You have to add a .travis.yml file (example. And enable testing for the repository here: https://travis-ci.org/profile.

    opened by asm89 4
  • Build files for PEAR Package

    Build files for PEAR Package

    • need to update information for package.ini (Onion package builder,bundler)
    • if possible, please to move lib/bootstrap.php to other place, since lib/ will be installed to pear directory, the bootstrap.php will be put into path like /opt/local/lib/php/pear/bootstraps.php and will cause namespace pollution.
    • if lib to src, then the roles section of package.ini can be ignored.
    opened by c9s 4
  • Add HashMap::keys() to allow access to object keys

    Add HashMap::keys() to allow access to object keys

    This is more a bug report than an actual PR.

    I tried to add keys() to Map, but I have no clue how to make it work for SortedMap. This hack works for my specific case right now, so maybe including something like it is actually feasible...

    Please share your thoughts.

    opened by igorw 3
  • psr2 fixer run

    psr2 fixer run

    As the title says. One additional change is in the class HashMap, on line 32. The method isEmpty checks against the array count instead of using function empty()

    opened by hoshsadiq 2
  • Define Hashable Interface

    Define Hashable Interface

    For map implementation, expecially HashMap it advantage for us to define Hashable interface, this interface only require 2 method: hashCode and isEquals modeled after Java. The advantage having this interface are the HashMap no longer take hashfunction argument and move the responsibily of compare two key is equal to the interface. It maybe overkill what do you think?

    opened by syaiful6 3
  • Add map and filter algorithms

    Add map and filter algorithms

    PR #41 added Mappable and Filterable interfaces – this uses those to specialize functions map and filter. This is experimental as well and would like some feedback if possible.

    opened by morrisonlevi 6
  • Create Filterable and Mappable attributes

    Create Filterable and Mappable attributes

    The idea here is is that some programmers may not want to implement all of the Collection interface. So by using interface segregation we can separate them out.

    I'm not completely sold on this idea, though, which is why this is a pull request. I'm hoping to get some feedback.

    opened by morrisonlevi 0
  • Should Ardent have a TypeException?

    Should Ardent have a TypeException?

    I would throw an EngineException (PHP7) for consistency with PHP's own type hinting. Or, better, I'd use trigger_error() for PHP5 compatibility (which would presumably result in a EngineException in PHP7)

    opened by Wes0617 2
Owner
Levi Morrison
Levi Morrison
PHP Integrated Query, a real LINQ library for PHP

PHP Integrated Query - Official site What is PINQ? Based off the .NET's LINQ (Language integrated query), PINQ unifies querying across arrays/iterator

Elliot Levin 465 Dec 30, 2022
🗃 Array manipulation library for PHP, called Arrayy!

?? Arrayy A PHP array manipulation library. Compatible with PHP 7+ & PHP 8+ \Arrayy\Type\StringCollection::create(['Array', 'Array'])->unique()->appen

Lars Moelleken 430 Jan 5, 2023
Library for (de-)serializing data of any complexity (supports JSON, and XML)

jms/serializer Introduction This library allows you to (de-)serialize data of any complexity. Currently, it supports XML and JSON. It also provides yo

Johannes 2.2k Jan 1, 2023
:lipstick: Scalable and durable all-purpose data import library for publishing APIs and SDKs.

Porter Scalable and durable data imports for publishing and consuming APIs Porter is the all-purpose PHP data importer. She fetches data from anywhere

null 594 Jan 1, 2023
[READ-ONLY] Collection library in CakePHP. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Collection Library The collection classes provide a set of tools to manipulate arrays or Traversable objects. If you have ever used underscore

CakePHP 85 Nov 28, 2022
True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code. Uses the accepted Fibers RFC to be implemented into PHP 8.1

PHP Fibers - Async Examples Without External Dependencies True asynchronous PHP I/O and HTTP without frameworks, extensions, or annoying code behemoth

Cole Green 121 Jan 6, 2023
Map nested JSON structures onto PHP classes

JsonMapper - map nested JSON structures onto PHP classes Takes data retrieved from a JSON web service and converts them into nested object and arrays

Christian Weiske 1.4k Dec 30, 2022
Yet Another LINQ to Objects for PHP [Simplified BSD]

YaLinqo: Yet Another LINQ to Objects for PHP Online documentation GitHub repository Features The most complete port of .NET LINQ to PHP, with many add

Alexander Prokhorov 436 Jan 3, 2023
`LINQ to Object` inspired DSL for PHP

Ginq Array handling in PHP? Be happy with Ginq! Ginq is a DSL that can handle arrays and iterators of PHP unified. Ginq is inspired by Linq to Object,

Atsushi Kanehara 191 Dec 19, 2022
A repository with implementations of different data structures and algorithms using PHP

PHP Data Structures and Algorithms Data structure and Algorithm is always important for any programming language. PHP, being one of the most popular l

Mizanur Rahman 610 Jan 2, 2023
Leetcode for PHP, five questions a week and weekends are updated irregularly

✏️ Leetcode for PHP why do you have to sleep for a long time ,and naturally sleep after death 联系 说明 由于目前工作主要是 golang,我又新起了一个LeetCode-Go-Week项目,- Leetc

吴亲库里 370 Dec 29, 2022
Missing data types for PHP. Highly extendable.

Neverending data validation can be exhausting. Either you have to validate your data over and over again in every function you use it, or you have to rely it has already been validated somewhere else and risk potential problems.

SmartEmailing 82 Nov 11, 2022
JsonMapper - map nested JSON structures onto PHP classes

Takes data retrieved from a JSON web service and converts them into nested object and arrays - using your own model classes.

Netresearch 9 Aug 21, 2022
All Algorithms implemented in Php

The Algorithms - PHP All algorithms implemented in Php (for education) These implementations are for learning purposes. They may be less efficient tha

The Algorithms 1k Dec 27, 2022
A community driven collection of sorting algorithms in PHP

algorithms A community driven collection of sorting algorithms This repository includes a comma separated file that includes 10k numbers between 1 and

Andrew S Erwin 0 May 16, 2022
Iterators - The missing PHP iterators.

PHP Iterators Description The missing PHP iterators. Features CachingIteratorAggregate ClosureIterator: ClosureIterator(callable $callable, array $arg

(infinite) loophp 24 Dec 21, 2022
Collections Abstraction library for PHP

Collections Collections Abstraction library for PHP The Collection library is one of the most useful things that many modern languages has, but for so

Ítalo Vietro 62 Dec 27, 2021
QuidPHP/Main is a PHP library that provides a set of base objects and collections that can be extended to build something more specific.

QuidPHP/Main is a PHP library that provides a set of base objects and collections that can be extended to build something more specific. It is part of the QuidPHP package and can also be used standalone.

QuidPHP 4 Jul 2, 2022
🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Andrea Marco Sartori 61 Dec 3, 2022
Load files and classes as lazy collections in Laravel.

Lody Load files and classes as lazy collections in Laravel. Installation composer require lorisleiva/lody Usage Lody enables you to fetch all exist

Loris Leiva 64 Dec 22, 2022