PHP-ruler – strict rule engine in pure PHP, zero deps, explain mode
FreeAbout PHP-ruler – strict rule engine in pure PHP, zero deps, explain mode
PHP-ruler is an open-source rule engine that evaluates business rules stored as strings, with strict typing, zero dependencies, and a unique explain mode that traces node-by-node why a rule passed or failed. It allows developers to move business logic (pricing, eligibility, feature flags, validation, content filters) out of code and into runtime-evaluated expressions, enabling rule changes without redeployment. The engine is safe to expose to semi-trusted rule authors because it never touches objects, methods, or PHP internals. Key features include strict type evaluation (no coercion), safe mode for collecting all missing variables at once, variable aliasing, AST caching/export, custom function registration, and a clear error model with typed exceptions. Requires PHP 8.1+ and no additional extensions.
Key Features
Pros & Cons
- Strict typing prevents silent bugs from type coercion
- Explain mode makes it easy to debug and audit rule evaluations
- Safe mode is useful for batch validation and reporting all errors
- Zero dependencies simplifies integration and maintenance
- Variable aliasing improves readability when non-developers author rules
- AST caching and export improve performance for repeated evaluations
- Cannot access object properties or call methods within expressions
- Not suitable for complex expression needs like Symfony ExpressionLanguage or Twig
- Requires PHP 8.1 or higher, excluding older PHP installations