PHP code example of fly321 / rule-engine

1. Go to this page and download the library: Download fly321/rule-engine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fly321 / rule-engine example snippets




namespace Fly\RuleEngine\Rules;

use Fly\RuleEngine\Interfaces\RuleContextInterface;
use Fly\RuleEngine\Interfaces\RuleInterface;

class DemoRule implements RuleInterface
{
    /**
     * @inheritDoc
     */
    public function matches(RuleContextInterface $context): bool
    {
        return $context->containsKey("num1")
            &&
            $context->containsKey("num2")
            &&
            $context->get("num1") < $context->get("num2");
    }

    /**
     * @inheritDoc
     */
    public function execute(RuleContextInterface $context): void
    {
        var_dump($context->get("num1"), $context->get("num2"));
        echo "num1 < num2\n";
        $context->set("num_bool", true);
    }

    /**
     * @inheritDoc
     */
    public function notMatches(RuleContextInterface $context): void
    {
        var_dump($context->get("num1"), $context->get("num2"));
        echo "num1 >= num2\n";
        $context->set("num_bool", false);
    }
}
sh
   php test/demo.php