-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-loader.php
More file actions
37 lines (28 loc) · 841 Bytes
/
Copy pathjson-loader.php
File metadata and controls
37 lines (28 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
use RuleFlow\Engine;
use RuleFlow\Loaders\JsonRuleLoader;
use RuleFlow\Validation\RuleValidator;
require __DIR__ . '/../vendor/autoload.php';
$rulesPath = __DIR__ . '/rules/order-risk.json';
$rules = json_decode((string) file_get_contents($rulesPath), true, 512, JSON_THROW_ON_ERROR);
$validation = RuleValidator::defaults()->validate($rules);
if (!$validation->valid()) {
echo "Invalid rules:\n";
echo implode("\n", $validation->errors());
exit(1);
}
$context = [
'user' => [
'id' => 1001,
'risk_score' => 45,
'days_since_signup' => 3,
],
'order' => [
'id' => 'ORD-1001',
'amount' => 1299,
],
];
$ruleSet = (new JsonRuleLoader($rulesPath))->load();
$result = Engine::make($ruleSet)->evaluate($context);
print_r($result->toArray());