villaflor/decree

Rule Engine

Fund package maintenance!
villaflor

1.0.0 2022-12-25 18:46 UTC

README

Latest Version on Packagist PHP Version Supported License Total Downloads Tests

Chain Command.

Installation

You can install the package via composer:

composer require villaflor/decree

Usage

$data = [
    'roi' => 1
];

// action list
$noAction = new NoAction();
$terminalLog = new TerminalLog();

//rule list
$isRoiGreaterThan1 = new GreaterThan($data['roi'], 1);
$isRoiLessThan1 = new LessThan($data['roi'], 1);
$isRoiEquals1 = new Equals($data['roi'], 1);
$isRoiEquals1Strict = new Equals($data['roi'], 1, true);

$secondNode = new Node([
    [
        'rule' => $isRoiEquals1,
        'next' => $noAction,
    ],
    [
        'rule' => $isRoiEquals1,
        'next' => $terminalLog,
    ],
]);
$firstNode = new Node([
    [
        'rule' =>$isRoiEquals1Strict,
        'next' => $secondNode,
    ],
    [
        'rule' => $isRoiGreaterThan1,
        'next' => $terminalLog,
    ],
    [
        'rule' => $isRoiLessThan1,
        'next' => $terminalLog,
    ]
]);

$x = $firstNode->handle($data);

var_dump($x);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.