1. Go to this page and download the library: Download fr3on/php-ruleset 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/ */
fr3on / php-ruleset example snippets
use Fr3on\Ruleset\Ruleset;
$ruleset = new Ruleset();
$rule = 'order.total * 1.15 > 1000 AND user.country IN ["SA", "AE"]';
$data = [
'order' => ['total' => 1000],
'user' => ['country' => 'SA']
];
$result = $ruleset->execute($rule, $data); // true
$ruleset->registerFunction('is_premium', fn($userId) => $db->isPremium($userId));
$ruleset->execute('is_premium(user.id) AND order.discount > 0.2', $data);
$ast = $ruleset->parse('x > 10');
// Reuse $ast across many evaluations
$result = $ruleset->evaluate($ast, ['x' => 15]);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.