1 | <?php |
||
21 | class FormulaEngine |
||
22 | { |
||
23 | protected $ruler; |
||
24 | |||
25 | protected $asserter; |
||
26 | |||
27 | protected $context; |
||
28 | |||
29 | protected $discount; |
||
30 | |||
31 | 1 | public function __construct() |
|
32 | { |
||
33 | 1 | if (!class_exists(Context::class)) { |
|
34 | throw new \Exception('to use formula engine install `hoa/ruler`'); |
||
35 | } |
||
36 | 1 | } |
|
37 | |||
38 | /** |
||
39 | * @param string $formula |
||
40 | * @return ChargeModifier |
||
41 | */ |
||
42 | 1 | public function build(string $formula): ChargeModifier |
|
43 | { |
||
44 | 1 | return $this->getRuler()->assert($formula, $this->getContext()); |
|
45 | } |
||
46 | |||
47 | 1 | public function getRuler() |
|
48 | { |
||
49 | 1 | if ($this->ruler === null) { |
|
50 | 1 | $this->ruler = new Ruler(); |
|
51 | 1 | $this->ruler->setAsserter($this->getAsserter()); |
|
52 | } |
||
53 | |||
54 | 1 | return $this->ruler; |
|
55 | } |
||
56 | |||
57 | 1 | public function getAsserter() |
|
65 | |||
66 | 1 | public function getContext() |
|
74 | |||
75 | 1 | protected function buildContext() |
|
82 | |||
83 | 1 | public function getDiscount() |
|
84 | { |
||
85 | 1 | if ($this->discount === null) { |
|
91 | } |
||
92 |