1. Go to this page and download the library: Download antonforwork/rules 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/ */
antonforwork / rules example snippets
$rule1 = new \Rules\Rule(['id'=>1, 'name'=>'cart discount', '...etc']);
$rule1->withPredicate(new \Rules\Predicates\Primitives\Gte('total_amount', 4500));
$rule2 = new \Rules\Rule(['id'=>2, 'name'=>'country based promo', '...etc']);
$rule2->withPredicate(new \Rules\Predicates\Primitives\Equals('country','US'));
// build context
$context = new \Rules\Contexts\ArrayContext([
'country'=> 'US',
'total_amount'=> 3000,
]);
$manager = new \Rules\Manager();
$manager
->addRule($rule1)
->addRule($rule2)
// ...
;
$matchedRules = $manager->inspect($context); // will return only 1 item. Rule #2, country based promo