dev-master
9999999-dev https://github.com/rezzza/RulerBundleA simple stateless production rules engine for Symfony 2.
MIT
The Requires
- symfony/framework-bundle ~2.1
- hoa/ruler ~1.0
- php >=5.4.0
bundle symfony ruler
Wallogit.com
2017 © Pedro Peláez
A simple stateless production rules engine for Symfony 2.
A simple stateless production rules engine for Symfony 2., (*1)
Integration of Hoa\Ruler library., (*2)
rezzza_ruler:
context_builder: service.id
# or
#context_builder:
# default: service.id
events:
event.cart.paid: 'Cart paid'
# or
event.cart.paid:
label: 'Cart paid'
context_builder: default
inferences:
cart.price_total:
# This will show this inferences only when event event.cart.paid
# will be selected on UI.
# This is optional.
event: [event.cart.paid]
type: decimal
description: Cart total price is
cart.created_at:
type: date
description: Cart was created at
cart.contain_product:
type: product
# Your own type
# You'll return a list of product as array.
# Not yet implemented, we'll have to finish ui via forms.
description: Cart contain product
<?php
$rb = $container->get('rezzza.ruler.rule_builder');
$rule = $rb->and(
$rb->{'>='}($rb->variable('cart.price_total'), 100),
$rb->{'>='}($rb->context('cart.created_at'), '2011-06-10')
);
$context = $container->get('rezzza.ruler.context_builder')->createContext('default');
$context = $container->get('rezzza.ruler.context_builder')->createContextFromEvent('event.cart.paid');
echo $container->get('rezzza.ruler')->assert($rule, $context); // true or false
To store rules on a storage, you can serialize it, store it on storage, fetch it from storage, and deserialize it. Context does not stay on storage., (*3)
$rb = $container->get('rezzza.ruler.rule_builder'); $rule = $rb->and( $rb->{'>='}($rb->context('cart.price_total'), 100), $rb->{'>='}($rb->context('cart.created_at'), '2011-06-10') ); $string = (string) $rule; // cart.price.total >= 100 AND cart.created_at >= 2011-06-10 $rule = $container->get('rezzza.ruler')->interprete($string);
Define a service with rezzza.ruler.functions tag., (*4)
<service id="acme.ruler.functions" class="Acme\Ruler\Functions">
<tag name="rezzza.ruler.functions" />
</service>
Then the php class:, (*5)
<?php
namespace Acme\Ruler\Functions;
use Rezzza\RulerBundle\Ruler\FunctionCollectionInterface;
class FunctionCollection implements FunctionCollectionInterface
{
public function getFunctions()
{
return array(
'version_compare' => function($left, $comparator, $right) {
return version_compare($left, $comparator, $right);
},
);
}
}
That's all folks !, (*6)
Any idea, suggestion ? Create an issue., (*7)
A simple stateless production rules engine for Symfony 2.
MIT
bundle symfony ruler