1 | <?php |
||
8 | class ValueResult { |
||
9 | private $result = []; |
||
10 | /* |
||
11 | The next operation to perform. Will be one of the following: |
||
12 | ARG - A new value e.g, "a","b" becomes ["a", "b"] |
||
13 | CONCAT - Concat onto the current arg e.g "a" + "b" becomes ["ab"] |
||
14 | NOT - Boolean operation "a" != "b" becomes [true] |
||
15 | EQUALS - Boolean operation "a" = "b" becomes [false] |
||
16 | */ |
||
17 | private $mode = Tokenizer::ARG; |
||
18 | |||
19 | //Processes $newValue using $mode. Either concats to the current argument, adds a new argument |
||
20 | //Or usess the two arguments for a boolean comparison |
||
21 | public function processValue($newValue) { |
||
22 | $funcs = [ |
||
23 | Tokenizer::ARG => 'arg', |
||
24 | Tokenizer::CONCAT => 'concat', |
||
25 | Tokenizer::EQUALS => 'equals', |
||
26 | Tokenizer::NOT => 'not', |
||
27 | Tokenizer::SUBTRACT => 'sub', |
||
28 | Tokenizer::MULTIPLY => 'mult', |
||
29 | Tokenizer::DIVIDE => 'div', |
||
30 | Tokenizer::GREATER_THAN => 'greater', |
||
31 | Tokenizer::LOWER_THAN => 'lower', |
||
32 | Tokenizer::IN => 'in' |
||
33 | ]; |
||
34 | |||
35 | if ($funcs[$this->mode] === 'concat' && is_numeric($newValue) |
||
36 | && is_numeric($this->result[count($this->result)-1])) |
||
37 | $this->add($newValue); |
||
38 | else |
||
39 | $this->{$funcs[$this->mode]}($newValue); |
||
40 | } |
||
41 | |||
42 | public function in($value) { |
||
46 | |||
47 | public function arg($value) { |
||
50 | |||
51 | public function concat($value) { |
||
52 | $this->result[count($this->result)-1] .= $value; |
||
53 | } |
||
54 | |||
55 | public function not($value) { |
||
58 | |||
59 | public function equals($value) { |
||
60 | $this->result[count($this->result)-1] = $this->result[count($this->result)-1] == $value; |
||
61 | } |
||
62 | |||
63 | public function greater($value) { |
||
64 | $this->result[count($this->result)-1] = $this->result[count($this->result)-1] > $value; |
||
65 | } |
||
66 | |||
67 | public function lower($value) { |
||
68 | $this->result[count($this->result)-1] = $this->result[count($this->result)-1] < $value; |
||
69 | } |
||
70 | |||
71 | public function add($value) { |
||
72 | $this->result[count($this->result)-1] += $value; |
||
73 | } |
||
74 | |||
75 | public function sub($value) { |
||
76 | $this->result[count($this->result)-1] -= $value; |
||
77 | } |
||
78 | |||
79 | public function mult($value) { |
||
80 | $this->result[count($this->result)-1] *= $value; |
||
81 | } |
||
82 | |||
83 | public function div($value) { |
||
84 | $this->result[count($this->result)-1] /= $value; |
||
85 | } |
||
86 | |||
87 | public function setMode($mode) { |
||
90 | |||
91 | public function getMode() { |
||
94 | |||
95 | public function getResult() { |
||
98 | |||
99 | public function pop() { |
||
102 | |||
103 | private function write($index, $value, $allowNull = false) { |
||
108 | |||
109 | //Postprocessing - replace values with null where allowed, or override a value at position |
||
110 | public function postProcess(ValueData $data, $val, $overrideVal, $allowNull) { |
||
119 | |||
120 | public function clear() { |
||
123 | } |
||
124 |