PHPackages                             danbettles/gestalt - 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. danbettles/gestalt

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

danbettles/gestalt
==================

Provides classes that implement basic patterns involving collections. Key components are a class implementing a simplified filter-chain pattern, `SimpleFilterChain`, and a simple array class, `ArrayObject`.

v4.0.0(4y ago)11.6k—0%1ISCPHPPHP ^7.4|^8.0

Since Apr 27Pushed 4y ago1 watchersCompare

[ Source](https://github.com/danbettles/gestalt)[ Packagist](https://packagist.org/packages/danbettles/gestalt)[ RSS](/packages/danbettles-gestalt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (1)

Gestalt
=======

[](#gestalt)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/09a279f1a93093fe57e6b1a50af541fc4491af2350694fc7f364564acc6c066c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64616e626574746c65732f67657374616c742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/danbettles/gestalt/?branch=main) [![Code Coverage](https://camo.githubusercontent.com/6cdd2bcafca1785ce9b9aa088e4a5bf3325b42d0c83c11fd6e0bb9e1d997ef97/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64616e626574746c65732f67657374616c742f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/danbettles/gestalt/?branch=main) [![Build Status](https://camo.githubusercontent.com/c741751a5a47586bac46e92ac25f9ca3e569f059dcde357255f76c9c3f87631f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64616e626574746c65732f67657374616c742f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/danbettles/gestalt/build-status/main)

Provides classes that implement basic patterns involving collections. Key components are a class implementing a simplified filter-chain pattern, `SimpleFilterChain`, and a simple array class, `ArrayObject`.

SimpleFilterChain
-----------------

[](#simplefilterchain)

A simple unidirectional filter chain.

### -&gt;execute(mixed &amp;$request, \[mixed $valueToBreak = false\])

[](#-executemixed-request-mixed-valuetobreak--false)

Invokes each filter in turn; the specified 'request' will be passed to each filter.

Iteration will stop if a filter returns the value of `$valueToBreak`. If iteration is forcibly stopped then the method will return the value of `$valueToBreak`. If, however, iteration is allowed to continue until completion then the method will return `null`.

```
use DanBettles\Gestalt\SimpleFilterChain;

$chain = (new SimpleFilterChain([
    function (&$request) {
        $request[] = 1;
    },
    function (&$request) {
        $request[] = 2;
        return false;
    },
    function (&$request) {
        $request[] = 3;
    },
]));

$request = [];

$returnValue = $chain->execute($request);

\assert($request === [1, 2]);
\assert($returnValue === false);
```

ArrayObject
-----------

[](#arrayobject)

A simple array class. Instances are mutable (i.e. methods change the state of the object).

### -&gt;sortByKey(\[array $order = array()\])

[](#-sortbykeyarray-order--array)

When no arguments are passed, behaves the same as [ksort()](https://www.php.net/manual/en/function.ksort.php).

```
use DanBettles\Gestalt\ArrayObject;

$result = (new ArrayObject([
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => 'quuz',
    'corge' => 'grault',
]))
    ->sortByKey()
    ->getElements()
;

\assert($result === [
    'baz' => 'qux',
    'corge' => 'grault',
    'foo' => 'bar',
    'quux' => 'quuz',
]);
```

Otherwise, the elements can be put in the order specified in `$order`; this applies to arrays with numeric or non-numeric keys.

```
use DanBettles\Gestalt\ArrayObject;

$elements = [
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => 'quuz',
    'corge' => 'grault',
];

$order = [
    'corge',
    'foo',
    'quux',
];

$result = (new ArrayObject($elements))
    ->sortByKey($order)
    ->getElements()
;

\assert($result === [
    'corge' => 'grault',
    'foo' => 'bar',
    'quux' => 'quuz',
    'baz' => 'qux',
]);
```

### -&gt;each(\\Closure $callback)

[](#-eachclosure-callback)

Executes the callback for each of the elements. The callback is passed the key and the value of the current element, in that order.

```
use DanBettles\Gestalt\ArrayObject;

$elements = [
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => 'quuz',
];

$output = [];

$arrayObject = (new ArrayObject($elements))->each(function ($key, $value) use (&$output) {
    $output[$key] = $value;
});

\assert($output === $elements);
```

`each()` will stop iterating if the callback returns exactly `false`.

```
use DanBettles\Gestalt\ArrayObject;

$output = [];

(new ArrayObject([
    'foo' => 'bar',
    'baz' => 'qux',
    'quux' => 'quuz',
]))->each(function ($key, $value) use (&$output) {
    $output[$key] = $value;
    return false;
});

\assert($output === [
    'foo' => 'bar',
]);
```

### -&gt;reindexByColumn(string $columnKey)

[](#-reindexbycolumnstring-columnkey)

Useful when working with collections of records (arrays/objects) of the same type. Could be used to reindex an array of records selected from a database, by the values from a particular column, for example.

```
use DanBettles\Gestalt\ArrayObject;

$output = (new ArrayObject([
    [
        'id' => 876,
        'name' => 'Foo',
    ], [
        'id' => 12,
        'name' => 'Bar',
    ], [
        'id' => 1093,
        'name' => 'Baz',
    ],
]))
    ->reindexByColumn('id')
    ->getElements()
;

\assert([
    876 => [
        'id' => 876,
        'name' => 'Foo',
    ],
    12 => [
        'id' => 12,
        'name' => 'Bar',
    ],
    1093 => [
        'id' => 1093,
        'name' => 'Baz',
    ],
] === $output);
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1483d ago

### Community

Maintainers

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

---

Top Contributors

[![danbettles](https://avatars.githubusercontent.com/u/736672?v=4)](https://github.com/danbettles "danbettles (14 commits)")[![RichAtPowderBlue](https://avatars.githubusercontent.com/u/47561048?v=4)](https://github.com/RichAtPowderBlue "RichAtPowderBlue (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/danbettles-gestalt/health.svg)

```
[![Health](https://phpackages.com/badges/danbettles-gestalt/health.svg)](https://phpackages.com/packages/danbettles-gestalt)
```

PHPackages © 2026

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