adachsoft/rule-evaluator-expression-language

Symfony ExpressionLanguage implementation of adachsoft/rule-evaluator-contract.

Maintainers

Package info

gitlab.com/a.adach/rule-evaluator-expression-language

Issues

pkg:composer/adachsoft/rule-evaluator-expression-language

Transparency log

Statistics

Installs: 5

Dependents: 0

Suggesters: 1

Stars: 0

v0.1.0 2026-08-10 07:23 UTC

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.