Download the PHP package kevintherm/exprc without Composer
On this page you can find all versions of the php package kevintherm/exprc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kevintherm/exprc
More information about kevintherm/exprc
Files in kevintherm/exprc
Package exprc
Short Description Convert expression string to in-memory evaluation, SQL syntax, or something else.
License MIT
Informations about the package exprc
Exprc
Exprc is a tiny, decoupled rule engine for PHP
It parses rule strings into an AST once, then lets you evaluate that AST with different backends:
- in-memory records
- Laravel query builders
- custom callback handlers
Prerequisites
- PHP 8.2+
Install
For Laravel QueryBuilder support:
Architecture
Rule string -> Lexer -> Parser -> AST -> Evaluator
Core parser and AST are framework-agnostic. Evaluators are swappable adapters.
Supported Operators
=/!=>/>=/</<=LIKE/NOT LIKEIN/NOT INCONTAINS/NOT CONTAINSIS NULL/IS NOT NULL
Logical Operators & Precedence
Exprc uses SQL-style keywords for logical operations. Symbols like && or || are not supported.
NOT: Inverts the following expression (Highest precedence)AND: Matches only if both sides are trueOR: Matches if either side is true (Lowest precedence)
Use parentheses ( ) to group expressions and override default precedence:
status = 'active' AND (priority = 'high' OR is_urgent = true)
Comparison Values
- Literals:
'strings',"strings",42,10.5,true,false,null - Identifiers: Unquoted words on the right side are treated as field paths (e.g.,
verified = original_verified) - Arrays:
['a', 'b']or(1, 2, 3)
Parse Once, Evaluate Many
Query Builder Usage (Laravel)
Exprc uses Laravel query methods for JSON paths and containment. No raw SQL is generated.
Field Access
Supported syntax for parser and in-memory backend:
- dot notation:
user.profile.name - bracket notation:
tags[0],metadata['key'] - wildcard notation:
items[*]
Array Literals
Use either brackets or parentheses:
['active', 'pending']('active', 'pending')[1, 'two', true, null][]or()
Extension & Customization
Exprc is designed to be highly extensible via composition and visitors.
AST Node Visitors
You can traverse the AST before evaluation for static analysis or transformation using the VisitorInterface.
Custom AST Nodes & Evaluator Hooks
All core classes are non-final. You can extend ComparisonNode to create specialized nodes (like VeloquentComparisonNode) or use evaluator hooks:
Extensible Parsing
The Lexer and Parser classes can be extended. Use the TokenRegistry to prepare for custom symbols (like @ for system variables or -> for JSON paths).
Notes
- AST nodes are
readonlyvalue objects (PHP 8.2+). - Metadata-aware nodes can be created by extending base node classes.
- Evaluators support standard hooks for plugin-like behavior.
IS NULLandIS NOT NULLare treated as first-classNullComparisonNodeobjects.