-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample.php
More file actions
39 lines (31 loc) · 792 Bytes
/
example.php
File metadata and controls
39 lines (31 loc) · 792 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
38
39
<?php declare(strict_types=1);
require_once "vendor/autoload.php";
final class Product
{
public string $name;
public int $price;
public function __construct($name, $price)
{
$this->name = $name;
$this->price = $price;
}
}
final class Cart
{
public array $products;
public function getTotal(): int
{
return array_sum($this->products);
}
}
$ruleEngine = new \RobbertStevens\RulesEngine([
fn($fact) => count($fact->products) > 3,
fn($fact) => $fact->getTotal() > 50,
fn($fact) => !empty(array_filter($fact->products, fn($product) => $product->name === "Cheese")),
]);
$cart = new Cart();
$cart->products = [
new Product("Cheese", 10),
new Product("Chips", 25),
];
var_dump($ruleEngine->validateAny($cart));