adachsoft / rule-evaluator-expression-language
Symfony ExpressionLanguage implementation of adachsoft/rule-evaluator-contract.
Package info
gitlab.com/a.adach/rule-evaluator-expression-language
pkg:composer/adachsoft/rule-evaluator-expression-language
Requires
- php: ^8.3
- adachsoft/rule-evaluator-contract: ^0.1
- symfony/expression-language: ^6.4 || ^7.0
Requires (Dev)
- adachsoft/php-code-style: ^0.5.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.3
- rector/rector: ^2.6
This package is not auto-updated.
Last update: 2026-08-11 03:40:12 UTC
README
Symfony ExpressionLanguage implementation of the adachsoft/rule-evaluator-contract package.
Requirements
- PHP 8.3 or higher
- Symfony ExpressionLanguage 6.4 or 7.x
Installation
composer require adachsoft/rule-evaluator-expression-language
Usage
Create an evaluator through the factory:
use AdachSoft\RuleEvaluatorContract\Vo\RuleExpressionVo;
use AdachSoft\RuleEvaluatorExpressionLanguage\ExpressionLanguageRuleEvaluatorFactory;
$evaluator = (new ExpressionLanguageRuleEvaluatorFactory())->createDefault();
$isEligible = $evaluator->evaluate(
new RuleExpressionVo("data['order_total'] > 100"),
['data' => ['order_total' => 150]],
);
The evaluator returns a boolean. Syntax errors, evaluation failures, and expressions that return a non-boolean value are reported as RuleEvaluationFailedException.
Expression syntax
Expressions use the native Symfony ExpressionLanguage syntax. Access nested array values with bracket notation, for example:
new RuleExpressionVo("data['user']['role'] == 'admin'");
Use ['key'] to access array values. Dot notation such as data.user.role is not the syntax for nested arrays.
Both word and symbolic logical operators are supported:
data['active'] and data['enabled']
data['active'] && data['enabled']
Custom ExpressionLanguage configuration
Use create() when the application needs custom functions or a configured ExpressionLanguage instance:
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
$expressionLanguage = new ExpressionLanguage();
$expressionLanguage->register(
'is_admin',
static fn (string $role): bool => $role === 'admin',
static fn (string $role): string => sprintf('(%s === "admin")', $role),
);
$evaluator = (new ExpressionLanguageRuleEvaluatorFactory())->create($expressionLanguage);
The factory is the public creation API; the concrete evaluator is an internal implementation detail.