linio / rule-engine
Versatile rule engine that allows to apply logic to a given context.
Installs: 4 041
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 56
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- linio/common: ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-28 19:16:29 UTC
README
This is a small and versatile rule engine that allows you run conditional logic and predetermined statements on a given context. It has a Parser that targets a very simplistic AST. By default, we have included a Blockly XML parser, but you can add pretty much anything else.
Install
The recommended way to install Linio Rule Engine is through composer.
{ "require": { "linio/rule-engine": "^1.0" } }
Tests
To run the test suite, you need install the dependencies via composer, then run PHPUnit.
$ composer install
$ phpunit
Usage
The RuleEngine interpreter uses a parser to create the AST tree based on a provided
string, which is the actual rule source. You can create your own parser or use an
existing one, like the BlocklyXmlParser
. A context must be an instance of a Dictionary
.
<?php use Linio\Type\Dictionary; use Linio\Component\RuleEngine\Interpreter; $context = new Dictionary(['item' => 11]); $interpreter = new Interpreter(); $interpreter->setParser(...); $interpreter->evaluate('rule source', $context);