bednic / rich-expression-builder
This package is abandoned and no longer maintained.
The author suggests using the jaspr/expression package instead.
Rich expression builder allows create complex closure expression tree to filter array of objects
2.0.0
2022-06-14 20:56 UTC
Requires
- php: ^8.1
Requires (Dev)
- ext-pdo: *
- ext-pdo_sqlite: *
- doctrine/collections: ^1.6
- doctrine/orm: ^2.7
- phpstan/phpstan: ^1.4.10
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
README
Is a tool for creating expression tree to filter collection of objects. The main task is to be able filter object in array by their properties. Additionally, I will add SQLResolver to create WHERE filter for your query.
Example
<?php
$obj1 = new \stdClass();
$obj1->field = 1;
$obj2 = new \stdClass();
$obj2->field = 2;
$arr = [$obj1, $obj2];
$expression = Ex::and(
Ex::eq(Ex::field('field'), Ex::literal(1)),
Ex::gt(Ex::field('field'), Ex::literal(0))
);
$resolver = new ClosureResolver();
$filter = $resolver->dispatch($expression);
$result = array_filter($arr, $filter);
Result
array(1) { [0] => class stdClass#410 (1) { public $field => int(1) } }