mpoiriert/business-rule-engine-bundle

dev-master 2014-03-27 13:00 UTC

This package is auto-updated.

Last update: 2024-04-09 12:46:05 UTC


README

Build Status

Integration of the BusinessRuleEngine as a Symfony bundle.

You should read the Business Rule Engine documentation to know how and why to use it. The current documentation is meant to explain and to enable it and configure it in symfony.

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Nucleus\Bundle\BusinessRuleEngineBundle\NucleusBusinessRuleEngineBundle(),
    // ...
);

From there you can use the BusinessRuleEngine.

The service is named nucleus.business_rule_engine so you can access it via the service container like this:

<?php

$businessRuleEngine = $serviceContainer->get('nucleus.business_rule_engine');

Or injecting it in your service. Be sure to use the interface Nucleus\BusinessRuleEngine\IBusinessRuleEngine when you are referencing the object.

Adding a service as a rule

To add a service as a rule you need to tag the specific service.

<service id="my_namespace.my_module.my_service" class="MyNamespace\MyModule\MyServiceClass">
    <tag name="nucleus.business_rule_engine.rule" ruleName="myRuleName" />
</service>

The example is in xml, refer to symfony doc to know how to tag in YML or PHP.

The tag named nucleus.business_rule_engine.rule is use by this bundle to know witch service are a rule. The attribute ruleName will be the one you must refer when calling the business rule engine.

Since the BusinessRuleEngine is expecting a callable to be a rule, be sure to implement the __invoke magic method in php on your service.

<?php

namespace MyNamespace\MyModule;

class MyServiceClass
{
    /* ... */

    public function __invoke($toto)
    {
        /* ... do processing ... */

        return $result;//The business rule engine expect to receive a boolean value in return
    }
}

In the bundle we are implementing a IRuleProvider that is ContainerAware so service will not be loaded until you call a rule.

documentation for the integration in symfony