Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A simple stateless production rules engine for PHP 5.3.
tree: 3949f4a253

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src/Ruler
tests
vendor
.gitmodules
LICENSE
README.markdown
phpunit.xml.dist

README.markdown

Ruler

Ruler is a simple stateless production rules engine for PHP 5.3.

Ruler uses a pretty straightforward DSL provided by the RuleBuilder:

<?php

$rb = new RuleBuilder();
$rule = $rb->create(
    $rb->logicalAnd(
        $rb['minNumPeople']->lessThanOrEqualTo($rb['actualNumPeople']),
        $rb['maxNumPeople']->greaterThanOrEqualTo($rb['actualNumPeople'])
    ),
    function() {
        echo 'YAY!';
    }
);

$context = new Context(array(
    'minNumPeople' => 5,
    'maxNumPeople' => 25,
    'actualNumPeople' => function() {
        return 6;
    },
));

$rule->execute($context);

Of course, if you're not into the whole brevity thing, you can use it without a RuleBuilder:

<?php

$actualNumPeople = new Variable('actualNumPeople');
$rule = new Rule(
    new Operator\LogicalAnd(array(
        new Operator\LessThanOrEqualTo(new Variable('minNumPeople'), $actualNumPeople),
        new Operator\GreaterThanOrEqualTo(new Variable('maxNumPeople'), $actualNumPeople)
    )),
    function() {
        echo 'YAY!';
    }
);

$context = new Context(array(
    'minNumPeople' => 5,
    'maxNumPeople' => 25,
    'actualNumPeople' => function() {
        return 6;
    },
));

$rule->execute($context)
Something went wrong with that request. Please try again.