https://github.com/nicoswd/rule-engine-bundle
Symfony Rule Engine Bundle - Parses & Evaluates Rules Written in a JavaScript-like Syntax
https://github.com/nicoswd/rule-engine-bundle
business-rules domain-specific-language dsl evaluator rule rule-engine rules-engine symfony symfony-bundle symfony3
Last synced: 10 months ago
JSON representation
Symfony Rule Engine Bundle - Parses & Evaluates Rules Written in a JavaScript-like Syntax
- Host: GitHub
- URL: https://github.com/nicoswd/rule-engine-bundle
- Owner: nicoSWD
- License: mit
- Created: 2017-10-12T20:26:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-27T10:52:42.000Z (almost 8 years ago)
- Last Synced: 2025-03-24T17:15:13.685Z (11 months ago)
- Topics: business-rules, domain-specific-language, dsl, evaluator, rule, rule-engine, rules-engine, symfony, symfony-bundle, symfony3
- Language: PHP
- Homepage:
- Size: 43.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Symfony Rule Engine Bundle
==========================


[](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/?branch=master)
[](https://packagist.org/packages/nicoswd/symfony-rule-engine-bundle)
[](https://insight.sensiolabs.com/projects/4a70db5d-43a9-4763-8168-60f0ac761f33)
This package bundles [nicoSWD/php-rule-parser](https://github.com/nicoSWD/php-rule-parser)
Requires PHP >= 7.0
Compatible with Symfony 3 and 4!
Install
=======
```shell
$ composer require nicoswd/symfony-rule-engine-bundle
```
```php
'-'];
$result = $this->get('rule_parser')->isTrue($rule, $variables);
var_dump($result); // bool(true)
```
Custom Functions
================
Custom functions are automatically discovered. They just need to be configured
as service with the tag `nico_swd.rule.function`.
If you have multiple functions inside the same directory, the easiest way to make
them visible to the bundle is this:
_services.yml_
```yaml
AppBundle\Functions\:
resource: '../../src/AppBundle/Functions'
tags: ['nico_swd.rule.function']
```
Furthermore, custom functions must implement `nicoSWD\Rules\Core\CallableUserFunction`
like in the example below
```php
toArray()
)
)
);
}
public function getName(): string
{
return 'array_filter';
}
}
```
The functions optionally retrieve instances of `nicoSWD\Rules\Tokens\BaseToken` as arguments,
and always must return one as well.
```php
get('rule_parser')->isTrue($rule);
var_dump($result); // bool(true)
```