kachnitel / entity-expression-language
Evaluates Symfony ExpressionLanguage strings against PHP objects, resolving properties via PropertyAccess with optional is_granted() support
Package info
github.com/kachnitel/entity-expression-language
pkg:composer/kachnitel/entity-expression-language
Requires
- php: >=8.1
- symfony/expression-language: ^6.4|^7.0|^8.0
- symfony/property-access: ^6.4|^7.0|^8.0
- symfony/security-core: ^6.4|^7.0|^8.0
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^10.5|^11.0
This package is auto-updated.
Last update: 2026-03-14 19:24:51 UTC
README
Evaluates Symfony ExpressionLanguage strings against PHP objects, resolving properties through Symfony's PropertyAccess component with an optional is_granted() security function.
Installation
composer require kachnitel/entity-expression-language
Usage
use Kachnitel\EntityExpressionLanguage\EntityExpressionLanguage; $lang = new EntityExpressionLanguage(); // Simple property comparison — calls getStatus() automatically $lang->evaluate('entity.status == "pending"', $order); // bool // Boolean property — calls isActive() $lang->evaluate('entity.active', $product); // Numeric comparison $lang->evaluate('entity.stock > 0', $product); // Combined conditions $lang->evaluate('entity.status == "pending" && entity.stock > 0', $product); // "item" is an alias for "entity" $lang->evaluate('item.status == "draft"', $article); // Explicit method call syntax $lang->evaluate('entity.getStatus() == "pending"', $order);
Security checks with is_granted()
Pass an AuthorizationCheckerInterface as the third argument to enable is_granted():
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; $lang->evaluate( 'entity.status != "locked" && is_granted("ROLE_EDITOR")', $entity, $authorizationChecker, ); // Pass entity as subject to a voter $lang->evaluate('is_granted("ADMIN_EDIT", entity)', $entity, $authorizationChecker);
is_granted() returns false when no AuthorizationCheckerInterface is provided.
Error handling
Any parse or runtime error returns false — a misconfigured expression never throws.
Requirements
- PHP 8.1+
symfony/expression-language^6.4|^7.0|^8.0symfony/property-access^6.4|^7.0|^8.0symfony/security-core^6.4|^7.0|^8.0