The Rule Engine is a flexible and extensible framework for defining and evaluating rules and conditions, and executing corresponding actions based on specified conditions.
- PHP 8.1 or higher
- Composer
Install the package via Composer:
composer require maniaba/rule-engine
For detailed installation instructions and verification, see the Installation Documentation.
- 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
<?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);
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.
composer test
All notable changes to this project are documented in the CHANGELOG.md file.
Contributions are welcome! Please see CONTRIBUTING.md for details.
If you discover a security vulnerability, please send an email to maniaba@outlook.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.