Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: about 1 month ago
JSON representation

Symfony Rule Engine Bundle - Parses & Evaluates Rules Written in a JavaScript-like Syntax

Awesome Lists containing this project

README

        

Symfony Rule Engine Bundle
==========================

![build](https://travis-ci.org/nicoSWD/rule-engine-bundle.svg?branch=master)
![coverage](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/badges/coverage.png?b=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nicoSWD/rule-engine-bundle/?branch=master)
[![Latest Stable Version](https://img.shields.io/packagist/v/nicoswd/symfony-rule-engine-bundle.svg)](https://packagist.org/packages/nicoswd/symfony-rule-engine-bundle)

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/4a70db5d-43a9-4763-8168-60f0ac761f33/big.png)](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)
```