PHPackages                             di/expression-parser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. di/expression-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

di/expression-parser
====================

This package allows to evaluate (parse with mapping) large amounts of data in flexible manner, providing various processing functions

0.2.2(8y ago)128BSD-3-ClausePHPCI failing

Since Apr 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/matrunchyk/expression-parser)[ Packagist](https://packagist.org/packages/di/expression-parser)[ RSS](/packages/di-expression-parser/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (6)Versions (7)Used By (0)

⛓ Expression Parser v0.2.3
==========================

[](#-expression-parser-v023)

[![Build Status](https://camo.githubusercontent.com/b8f2cc3284e1c2a80378f9fe965b26e20da8cc43a4bb0718c009e0a7f74dd7cd/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d617472756e6368796b2f65787072657373696f6e2d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/matrunchyk/expression-parser)[![Last version](https://camo.githubusercontent.com/77de72a1e75886d5f04da9cde6434c474fd69f0733b85c0649ce47b5770ff4da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7061636b6167652d6a736f6e2f762f6261646765732f736869656c64732e737667)](https://camo.githubusercontent.com/77de72a1e75886d5f04da9cde6434c474fd69f0733b85c0649ce47b5770ff4da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7061636b6167652d6a736f6e2f762f6261646765732f736869656c64732e737667)[![License](https://camo.githubusercontent.com/c77e0a9f3eca708f759e1866f8ebe6e211083c52acb11cba15f26328d844267f/68747470733a2f2f706f7365722e707567782e6f72672f707567782f62616467652d706f7365722f6c6963656e73653f666f726d61743d666c6174)](https://camo.githubusercontent.com/c77e0a9f3eca708f759e1866f8ebe6e211083c52acb11cba15f26328d844267f/68747470733a2f2f706f7365722e707567782e6f72672f707567782f62616467652d706f7365722f6c6963656e73653f666f726d61743d666c6174)

This package allows to evaluate (parse with mapping) large amounts of data in flexible manner, providing various processing functions:

🔩 Install
---------

[](#-install)

`composer install di/expression-parser`

⚒ Usage
-------

[](#-usage)

```
// Signature
$expression = new Expression(string $expression[, array $mappings = []]);

```

👀 Example
---------

[](#-example)

```
use DI\ExpressionParser\Expression;

$expression = 'or_x(equal([attr1], 1), in_array(explode([keywords]), "hello"))';

$mappings = [
    'attr1' => 1,
    'keywords' => 'hello,world',
];

$ex = new Expression($expression, $mappings);

echo $ex->value(); // true

```

Standard function handlers
--------------------------

[](#standard-function-handlers)

#### 🔗 Parameter substitution

[](#-parameter-substitution)

📥 Input:

```
new Expression(
    '[attr1]',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `1`

#### 🔗 Parameter substitution with `has()` function

[](#-parameter-substitution-with-has-function)

📥 Input:

```
new Expression(
    'has([attr1])',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `true`

#### 🔗 Substitution with `in_array()` function and scalar value

[](#-substitution-with-in_array-function-and-scalar-value)

📥 Input:

```
new Expression(
    'in_array([keywords], "hello")',
    [
        'keywords' => [
            'hello',
            'world',
        ],
    ]
)

```

📤 Output: `true`

#### 🔗 Nested `in_array()` and `explode()` function and scalar value

[](#-nested-in_array-and-explode-function-and-scalar-value)

📥 Input:

```
new Expression(
    'in_array(explode([keywords]), "hello")',
    [
        'keywords' => 'hello,world',
    ]
)

```

📤 Output: `true`

#### 🔗 Substitution with `matches_in_array()` function

[](#-substitution-with-matches_in_array-function)

📥 Input:

```
new Expression(
    'matches_in_array([keywords], "pool")',
    [
        'keywords' => [
            'swimming pool',
        ],
    ]
)

```

📤 Output: `true`

#### 🔗 Nested `explode()` `is_empty()` and functions

[](#-nested-explode-is_empty-and-functions)

📥 Input:

```
new Expression(
    'is_empty(explode([keywords]))',
    [
        'keywords' => '',
    ]
)

```

📤 Output: `true`

#### 🔗 `implode()` with inline parameter substitution

[](#-implode-with-inline-parameter-substitution)

📥 Input:

```
new Expression(
    'implode(([attr1],[attr2]))',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `hello world`

#### 🔗 `implode()` with inline parameter substitution and a separator flag

[](#-implode-with-inline-parameter-substitution-and-a-separator-flag)

📥 Input:

```
new Expression(
    'implode(([attr1],[attr2]), ",")',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `hello,world`

#### 🔗 `explode()` with array substitution

[](#-explode-with-array-substitution)

📥 Input:

```
new Expression(
    'explode([Rooms])',
    [
        'Rooms' => 'Pantry,Study',
    ]
)

```

📤 Output: `['Pantry', 'Study']`

Standard handlers with one or multiple flags
--------------------------------------------

[](#standard-handlers-with-one-or-multiple-flags)

#### 🔗 `explode()` with array substitution and a separator flag

[](#-explode-with-array-substitution-and-a-separator-flag)

📥 Input:

```
new Expression(
    'explode([Rooms], ";")',
    [
        'Rooms' => 'Pantry;Study',
    ]
)

```

📤 Output: `['Pantry', 'Study']`

#### 🔗 `get()` function with `count` and `nullable` flags

[](#-get-function-with-count-and-nullable-flags)

📥 Input:

```
new Expression(
    'get([attr1], {"count":true, "nullable":false})',
    [
        'attr1' => [
            'a',
            'b',
            'c',
        ],
    ]
)

```

📤 Output: `3`

#### 🔗 Nested mapping with `map` flag in `get()` function

[](#-nested-mapping-with-map-flag-in-get-function)

📥 Input:

```
new Expression(
    'get([attr1], {"map":{"a":1, "b": 2, "c": 3}})',
    [
        'attr1' => 'b',
    ]
)

```

📤 Output: `2`

#### 🔗 Case sensitive matching in array with `sensitive` flag

[](#-case-sensitive-matching-in-array-with-sensitive-flag)

📥 Input:

```
new Expression(
    'matches_in_array([keywords], "pool", {"sensitive":true})',
    [
        'keywords' => [
            'Swimming Pool',
        ],
    ]
)

```

📤 Output: `false`

Logical handlers
----------------

[](#logical-handlers)

#### 🔗 `equal()` function

[](#-equal-function)

📥 Input:

```
new Expression(
    'equal([attr1], 1)',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `true`

#### 🔗 `great_than()` function

[](#-great_than-function)

📥 Input:

```
new Expression(
    'great_than([attr1], 0)',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `true`

#### 🔗 Nested `not()` and `equal()` functions

[](#-nested-not-and-equal-functions)

📥 Input:

```
new Expression(
    'not(equal([attr1], 2))',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `true`

#### 🔗 Nested `not()` and `equal()` functions

[](#-nested-not-and-equal-functions-1)

📥 Input:

```
new Expression(
    'not(equal([attr1], 2))',
    [
        'attr1' => 1,
        'attr2' => 2,
    ]
)

```

📤 Output: `true`

Complex functions with unlimited nesting level
----------------------------------------------

[](#complex-functions-with-unlimited-nesting-level)

#### 🔗 Multiple function parameter substitution with nesting with `and_x()`

[](#-multiple-function-parameter-substitution-with-nesting-with-and_x)

📥 Input:

```
new Expression(
    'and_x(equal([attr1], 1), in_array(explode([attr2]), "hello"))',
    [
        'attr1' => 1,
        'attr2' => 'hello,world',
    ]
)

```

📤 Output: `true`

#### 🔗 Multiple function parameter substitution with nesting with `or_x()`

[](#-multiple-function-parameter-substitution-with-nesting-with-or_x)

📥 Input:

```
new Expression(
    'or_x(equal([attr1], 1), in_array(explode([attr2]), "hello"))',
    [
        'attr1' => 1,
        'attr2' => 'hello,world',
    ]
)

```

📤 Output: `true`

#### 🔗 Multiple function parameter substitution with nesting with `or_x()` and `not()`

[](#-multiple-function-parameter-substitution-with-nesting-with-or_x-and-not)

📥 Input:

```
new Expression(
    'not(or_x(equal([attr1], 1), in_array(explode([attr2]), "word")))',
    [
        'attr1' => 2,
        'attr2' => 'hello,world',
    ]
)

```

📤 Output: `true`

#### 😳 Multiple nesting with a Closure

[](#-multiple-nesting-with-a-closure)

📥 Input:

```
new Expression(
    'first(take(sort(filter([attr1], [filter_func]), [dir]), [offset]))',
    [
        'attr1' => [
            10,
            30,
            20,
        ],
        'filter_func' => function (ExpressionParser $context, $value) {
            return array_filter($value, function ($item) use ($context) {
                return $item < $context->getMappings('filter_attr');
            });
        },
        'filter_attr' => 30,
        'dir' => 'desc',
        'offset' => 1,
    ]
)

```

📤 Output: `20`

`Laravel Collection` helpers
----------------------------

[](#laravel-collection-helpers)

The package already has a built-in support of Laravel Collection helpers. For more informations about the available functions it supports please refer to the original Laravel Collection [documentation page](https://laravel.com/docs/5.6/collections#available-methods).

#### 🔗 Example usage of Laravel Collection functions

[](#-example-usage-of-laravel-collection-functions)

📥 Input:

```
new Expression(
    'first(collect([attr1], [attr2]))',
    [
        'attr1' => 'value 1',
        'attr2' => 'value 2',
    ]
)

```

📤 Output: `'value 1'`

Extending with custom handlers
------------------------------

[](#extending-with-custom-handlers)

In order to extend or override current functionality, you will need to add your own handler class name to `config/handlers.php` file:

```
use DI\ExpressionParser\Handlers\Logical;
use DI\ExpressionParser\Handlers\Standard;
use DI\ExpressionParser\Handlers\LaravelCollectionAdapter;

return [
    Standard::class,
    Logical::class,
    LaravelCollectionAdapter::class,

    // Add custom expression handlers here:
    // \Acme\Handlers\CustomHandler::class,
    // 'Acme\Handlers\CustomHandler',
];

```

😍 Contribution
--------------

[](#-contribution)

Please feel free to fork and help developing.

📃 License
---------

[](#-license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

2995d ago

### Community

Maintainers

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

---

Top Contributors

[![matrunchyk](https://avatars.githubusercontent.com/u/2089828?v=4)](https://github.com/matrunchyk "matrunchyk (54 commits)")

---

Tags

compilerexpressionexpression-evaluatorexpression-parserlaravellibraryparserlaravelparserlibraryexpressioncompilerparsingevaluate

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/di-expression-parser/health.svg)

```
[![Health](https://phpackages.com/badges/di-expression-parser/health.svg)](https://phpackages.com/packages/di-expression-parser)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M337](/packages/psalm-plugin-laravel)[denissimon/formula-parser

Parsing and evaluating mathematical formulas given as strings.

81337.8k3](/packages/denissimon-formula-parser)[jejik/mt940

An MT940 bank statement parser for PHP

921.2M2](/packages/jejik-mt940)[mishal/iless

Less.js port to PHP

4738.2k3](/packages/mishal-iless)

PHPackages © 2026

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