1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Billing Library |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/php-billing |
6
|
|
|
* @package php-billing |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\formula; |
12
|
|
|
|
13
|
|
|
use Hoa\Ruler\Model; |
14
|
|
|
use Hoa\Ruler\Model\Bag\Context; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Andrii Vasyliev <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Asserter extends \Hoa\Ruler\Visitor\Asserter |
20
|
|
|
{ |
21
|
1 |
|
public function visitModel(Model $element, &$handle = null, $eldnah = null) |
22
|
|
|
{ |
23
|
1 |
|
return $element->getExpression()->accept($this, $handle, $eldnah); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Visit a method dimension. |
28
|
|
|
* |
29
|
|
|
* @param mixed &$contextPointer Pointer to the current context. |
30
|
|
|
* @param array $dimension Dimension bucket. |
31
|
|
|
* @param int $dimensionNumber Dimension number. |
32
|
|
|
* @param string $elementId Element name. |
33
|
|
|
* @param mixed &$handle Handle (reference). |
34
|
|
|
* @param mixed $eldnah Handle (not reference). |
35
|
|
|
* @return void |
36
|
|
|
* @throws \Hoa\Ruler\Exception\Asserter |
37
|
1 |
|
*/ |
38
|
|
|
protected function visitMethodDimension( |
39
|
|
|
&$contextPointer, |
40
|
|
|
array $dimension, |
41
|
|
|
$dimensionNumber, |
42
|
|
|
$elementId, |
43
|
|
|
&$handle = null, |
44
|
|
|
$eldnah = null |
45
|
1 |
|
) { |
46
|
1 |
|
$value = $dimension[Context::ACCESS_VALUE]; |
47
|
|
|
$method = $value->getName(); |
48
|
1 |
|
|
49
|
|
|
if (!is_object($contextPointer)) { |
50
|
|
|
throw new \Hoa\Ruler\Exception\Asserter( |
51
|
|
|
'Try to call an undefined method: %s ' . |
52
|
|
|
'(dimension number %d of %s), because it is ' . |
53
|
|
|
'not an object.', |
54
|
|
|
7, |
55
|
|
|
[$method, $dimensionNumber, $elementId] |
56
|
|
|
); |
57
|
|
|
} |
58
|
1 |
|
|
59
|
|
|
$arguments = []; |
60
|
1 |
|
|
61
|
1 |
|
foreach ($value->getArguments() as $argument) { |
62
|
|
|
$arguments[] = $argument->accept($this, $handle, $eldnah); |
63
|
|
|
} |
64
|
1 |
|
|
65
|
1 |
|
$contextPointer = call_user_func_array( |
66
|
1 |
|
[$contextPointer, $method], |
67
|
|
|
$arguments |
68
|
|
|
); |
69
|
1 |
|
|
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|