1 | <?php |
||
9 | class Value { |
||
10 | private $baseData; |
||
11 | private $autoLookup; |
||
12 | private $tokens; |
||
|
|||
13 | |||
14 | /* |
||
15 | Stores the last value e.g. |
||
16 | "a" + "b" |
||
17 | Will store "a" before reading the token for the + and perfoming the concatenate operation |
||
18 | */ |
||
19 | private $last; |
||
20 | private $data; |
||
21 | private $result; |
||
22 | |||
23 | private $tokenFuncs = [ |
||
24 | Tokenizer::NOT => 'processComparator', |
||
25 | Tokenizer::EQUALS => 'processComparator', |
||
26 | Tokenizer::DOT => 'processDot', |
||
27 | Tokenizer::OPEN_SQUARE_BRACKET => 'processSquareBracket', |
||
28 | Tokenizer::ARG => 'processSeparator', |
||
29 | Tokenizer::CONCAT => 'processSeparator', |
||
30 | Tokenizer::NAME => 'processScalar', |
||
31 | Tokenizer::NUMERIC => 'processScalar', |
||
32 | Tokenizer::BOOL => 'processScalar', |
||
33 | Tokenizer::STRING => 'processString', |
||
34 | Tokenizer::OPEN_BRACKET => 'processBrackets' |
||
35 | ]; |
||
36 | |||
37 | public function __construct($data, $autoLookup = false) { |
||
41 | |||
42 | public function parse($str) { |
||
48 | |||
49 | public function parseTokens($tokens, $data) { |
||
50 | $this->result = new ValueResult; |
||
51 | $this->data = new ValueData($data); |
||
52 | $this->last = null; |
||
53 | |||
54 | if (empty($tokens)) return [$data]; |
||
55 | |||
56 | foreach ($tokens as $token) { |
||
57 | $this->{$this->tokenFuncs[$token['type']]}($token); |
||
58 | } |
||
59 | |||
60 | $this->processLast(); |
||
61 | return $this->result->getResult(); |
||
62 | } |
||
63 | |||
64 | private function processComparator($token) { |
||
72 | |||
73 | |||
74 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
||
75 | |||
76 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
||
77 | private function processDot($token) { |
||
83 | |||
84 | private function processSquareBracket($token) { |
||
89 | |||
90 | private function processSeparator($token) { |
||
95 | |||
96 | private function processScalar($token) { |
||
99 | |||
100 | private function processString($token) { |
||
103 | |||
104 | private function processBrackets($token) { |
||
116 | |||
117 | private function processNested($token) { |
||
123 | |||
124 | private function callTransphpormFunctions($token) { |
||
132 | |||
133 | //Applies the current operation to whatever is in $last based on $mode |
||
134 | private function processLast() { |
||
152 | } |
This check marks private properties in classes that are never used. Those properties can be removed.