PHPackages                             arete/collection-pipeline - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arete/collection-pipeline

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arete/collection-pipeline
=========================

PHP (partial) implementation of a pipeline collection. Work with a collection of objects without making a bunch of callables, loops, &amp; ifs.

7251PHP

Since Oct 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/aretecode/collection-pipeline)[ Packagist](https://packagist.org/packages/arete/collection-pipeline)[ RSS](/packages/arete-collection-pipeline/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Arete\\CollectionPipeline
=========================

[](#aretecollectionpipeline)

[![Build Status](https://camo.githubusercontent.com/792db4b2d6e163c915e16b349ef752652efbbfb5200970fcb721292297dbc256/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6172657465636f64652f636f6c6c656374696f6e2d706970656c696e652e737667)](https://travis-ci.org/aretecode/collection-pipeline)[![HHVM Status](https://camo.githubusercontent.com/652d45a3280013b583d685e13f2ca0ba95ce47d7d43d32a6b81c6c158f1820f1/687474703a2f2f6868766d2e683463632e64652f62616467652f61726574652f636f6c6c656374696f6e2d706970656c696e652e737667)](http://hhvm.h4cc.de/package/arete/collection-pipeline)[![Author](https://camo.githubusercontent.com/3167ade4cb3531f4f057ab12d8ce359bb4507da73819d2d780cfcf216cbe7b63/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406172657465636f64652d626c75652e737667)](https://twitter.com/aretecode)[![Latest Unstable Version](https://camo.githubusercontent.com/2d17d325d8ff1ac1777ec028c15c3ec910035079803bf4c8852a26be0e79aec2/68747470733a2f2f706f7365722e707567782e6f72672f61726574652f636f6c6c656374696f6e2d706970656c696e652f762f756e737461626c65)](https://packagist.org/packages/arete/collection-pipeline)[![License](https://camo.githubusercontent.com/d57b3297230a1098597f1c0a495ba813af9a2453fc7b70c1e1deb7d353a1930b/68747470733a2f2f706f7365722e707567782e6f72672f61726574652f636f6c6c656374696f6e2d706970656c696e652f6c6963656e7365)](http://packagist.org/packages/arete/collection-pipeline)[![Codacy Badge](https://camo.githubusercontent.com/c7599522526584b98092c74a0a54af739a48d373dd1d6ca54463784b784f85bf/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f3838633862396635356366393465326162313637363561376339356265376161)](https://www.codacy.com/app/aretecode/collection-pipeline)

Work with a collection of objects without making a bunch of callables, loops, &amp; ifs.

After reading [Martin Fowler on the Collection Pipeline](http://martinfowler.com/articles/collection-pipeline/) I wanted to use something similar in PHP, thus, this was born. [League\\Pipeline](https://github.com/thephpleague/pipeline) was used as was [Illuminate\\Support\\Collection](http://laravel.com/api/master/Illuminate/Support/Collection.html) (all functions from this Collection are available in the chain.)

Example
=======

[](#example)

This is our example group we will use
-------------------------------------

[](#this-is-our-example-group-we-will-use)

```
use Arete\CollectionPipeline\CollectionPipeline as CP;

class MockEntity {
    public $id;
    public $name;
    public function __construct($id, $name) {
        $this->id = $id;
        $this->name = $name;
    }
    public function getId() {
        return $this->id;
    }
    public function getName() {
        return $this->name;
    }
}

// ids are just random for testing
$array = array(
    new MockEntity(null, "eric"), #0
    new MockEntity(10, "tim"),    #1
    new MockEntity(111, "beau"),  #2
    new MockEntity(11, "ross"),   #3
    new MockEntity(12, "sarah"),  #4
    new MockEntity(13, "taylor"), #5
    new MockEntity(-42, "lea"),   #6
    new MockEntity("eh", "phil"), #7
    new MockEntity(6, "larry"),   #8
    new MockEntity(10, "frank"),  #9
    new MockEntity(["eh"], "joe"),#10

    new MockEntity(99, "kayla"),  #12
    new MockEntity(0, "martin"),  #11
    new MockEntity(1, "brad"),    #13
    new MockEntity(2, "luke"),    #14
    new MockEntity(3, "paul"),    #15
    new MockEntity(4, "ash"),     #16
    new MockEntity(5, "davey"),   #17
    new MockEntity(18,"anthony"), #18
    new MockEntity(19,"tim"),     #19
);
```

String functions
----------------

[](#string-functions)

```
$result = CP::from($array)->wheres('getId', 'is_string')->all();

# gives: [7 => $array[7]]
```

`!` String functions
--------------------

[](#-string-functions)

```
$result = CP::from($array)->wheres('getId', '!is_string')->all();

# gives: everything in $array except #7
```

Each
----

[](#each)

Use `::wheresEach` to compare the whole value without using any accessors.

### instanceof

[](#instanceof)

```
$result = CP::from($array)->wheres('instanceof', MockEntity::CLASS)->all();

# gives: everything in $array
```

### `!` instanceof

[](#-instanceof)

```
$result = CP::from($array)->wheres('!instanceof', MockEntity::CLASS)->all();

# gives: empty array, they all are instances of MockEntity
```

[comparison operators](http://php.net/manual/en/language.operators.comparison.php)
----------------------------------------------------------------------------------

[](#comparison-operators)

[comparison operator tests](https://github.com/aretecode/collection-pipeline/blob/master/tests/MathComparisonTest.php)

```
$result = CP::from($array)->wheres('getId', '>', 110)->all();

# gives: [9 => $array[9]]
```

chaining
--------

[](#chaining)

```
$result = CP::from($array)->wheres('getId', '!is_string')->wheres('getId', '>', 10)->wheres('getName', '===', 'tim')->all();

# gives: [19 => $array[19]]
```

argument order:
---------------

[](#argument-order)

The accessor return value (X) as the first argument, and the value you are using in the comparison (Y).

```
// one does contain joe, but none contain derek
$stringItWouldBeIn = 'joe,derek';
$x = 'getName';
$y = $stringItWouldBeIn;

// containsSubString is from arete\support
$result = CP::from($array)->wheresYX($x, 'containsSubString', $y)->all();

# gives: [10 => $array[10]]
```

Laravel Illuminate:
-------------------

[](#laravel-illuminate)

Since it extends [Illuminate\\Support\\Collection](http://laravel.com/api/master/Illuminate/Support/Collection.html), you can use their functions, such as:

```
$result = CP::from($array)->wheres('id', 'is_string', null, 'property')->keys();

# gives: [7]
```

Types:
------

[](#types)

- [methods](https://github.com/aretecode/collection-pipeline/blob/master/tests/MethodTest.php)
- [properties](https://github.com/aretecode/collection-pipeline/blob/master/tests/PropertyTest.php)
- [callables (using closure)](https://github.com/aretecode/collection-pipeline/blob/master/tests/CallableTest.php)
- [key | index](https://github.com/aretecode/collection-pipeline/blob/master/tests/ArrayTest.php)By default it will first check if it's a `method`|`property`|`callable`|`index`. If you want to only check for that particular type, in this case, `method`:

```
// will only check for the method `getId`
$result = CP::from($array)->wheres('getId', '>', 110, 'method')->all();

# gives: [9 => $array[9]]
```

#### Reverse order

[](#reverse-order)

```
// compares 110 < $payload->getId()
$result = CP::from($array)->wheres('getId', ''` be able to do `('methodName', 'strlen >', 5)` (could use some Symfony\\ExpressionLanguage optionally if alias are required) when this is done, it will really use the pipeline how it ought to
- similar to the last todo, but with chaining method calls
- move examples out of readme (except for 1), and into \[examples/\]
- add in spaceship comparison operator depending on version (thanks @seldaek)
- `ands` using last method?
- refactor `ExendedPipeline` so it is less of a God object.
- array key in `Specification`
- array key for matching along with the method, property, and callable
- abstract argsOrderYX &amp; XY
- remove null check from `::wheresComparison`
- add ability to reverse arguments in expressions
- add casting of accessor
- add ::reduce() similar implementation as ::map()

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/da14182d4b58070a73351b3be3e65f9742754f58fe8a924b71ba908b4e0afe3b?d=identicon)[aretecode](/maintainers/aretecode)

---

Top Contributors

[![aretecode](https://avatars.githubusercontent.com/u/4022631?v=4)](https://github.com/aretecode "aretecode (26 commits)")

### Embed Badge

![Health badge](/badges/arete-collection-pipeline/health.svg)

```
[![Health](https://phpackages.com/badges/arete-collection-pipeline/health.svg)](https://phpackages.com/packages/arete-collection-pipeline)
```

###  Alternatives

[pragmarx/countries

PHP Countries and Currencies

1.9k3.3M18](/packages/pragmarx-countries)[inertiaui/modal

Inertia Modal

225213.5k](/packages/inertiaui-modal)[linkorb/jsmin-php

Unofficial package of jsmin-php

333.5M18](/packages/linkorb-jsmin-php)[qualityunit/tnef-decoder

TNEF Decoder library extracted from squirell mail plugin to decode winmail.dat file in email attachment

161.6M](/packages/qualityunit-tnef-decoder)[glpi-project/inventory_format

GLPI Inventory format lib

10451.7k](/packages/glpi-project-inventory-format)[shubhamjain/php-id3

A MP3 ID3 tags reader in native PHP

424.4k](/packages/shubhamjain-php-id3)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
