maniaba / rule-engine
A flexible and extensible framework for defining and evaluating rules and conditions, and executing corresponding actions based on specified conditions
Requires
- php: ^8.1
- symfony/polyfill-php83: ^1.32
Requires (Dev)
- dg/bypass-finals: ^1.9
- fakerphp/faker: ^1.9
- icanhazstring/composer-unused: dev-main
- mikey179/vfsstream: ^1.6
- nexusphp/cs-config: ^3.6
- nexusphp/tachycardia: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^2.0
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^10.5 || ^11.5 || ^12.0
- rector/rector: ^2.0
- roave/security-advisories: dev-latest
- vimeo/psalm: ^5.0 || ^6.0
This package is auto-updated.
Last update: 2025-07-21 08:38:37 UTC
README
The Rule Engine is a flexible and extensible framework for defining and evaluating rules and conditions, and executing corresponding actions based on specified conditions.
Requirements
- PHP 8.1 or higher
- Composer
Installation
Install the package via Composer:
composer require maniaba/rule-engine
For detailed installation instructions and verification, see the Installation Documentation.
Key Features
- Define rules using a structured array configuration
- Combine multiple conditions with logical operators (AND, OR)
- Execute actions based on condition results
- Extend with custom conditions and actions
- Validate rule configurations
Quick Example
<?php use Maniaba\RuleEngine\Builders\ArrayBuilder; use Maniaba\RuleEngine\Context\ArrayContext; // Create a builder $builder = new ArrayBuilder(); // Register an action $builder->actions()->registerAction('printMessage', function(ArrayContext $context, string $message) { echo "Message: {$message}\n"; return true; }); // Define a simple rule $config = [ 'node' => 'condition', 'if' => [ 'node' => 'context', 'contextName' => 'value', 'operator' => 'greaterThan', 'value' => 10, ], 'then' => [ 'node' => 'action', 'actionName' => 'printMessage', 'arguments' => [ 'message' => 'Value is greater than 10', ], ], ]; // Build and execute the rule $ruleSet = $builder->build($config); $context = new ArrayContext(['value' => 15]); $evaluator = new Maniaba\RuleEngine\Evaluators\BasicEvaluator(); $evaluator->execute(clone $ruleSet, $context);
Documentation
Comprehensive documentation is available at https://maniaba.github.io/rule-engine/, including:
- Detailed Configuration Guide
- Advanced Usage Examples
- Custom Conditions and Actions
- Validation and Error Handling
Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the rule engine? Feel free to create an issue on GitHub, we'll try to address it as soon as possible.
Testing
composer test
Changelog
All notable changes to this project are documented in the CHANGELOG.md file.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
Security
If you discover a security vulnerability, please send an email to maniaba@outlook.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.