1 | <?php |
||
12 | class CompiledExpression |
||
13 | { |
||
14 | /** |
||
15 | * Unknown type |
||
16 | */ |
||
17 | const UNKNOWN = Types::UNKNOWN_TYPE; |
||
18 | |||
19 | /** |
||
20 | * It's not unknown, It's unimplemented |
||
21 | */ |
||
22 | const UNIMPLEMENTED = -100; |
||
23 | |||
24 | /** |
||
25 | * Void type |
||
26 | */ |
||
27 | const VOID = Types::VOID_TYPE; |
||
28 | |||
29 | /** |
||
30 | * Integer type |
||
31 | */ |
||
32 | const INTEGER = Types::INT_TYPE; |
||
33 | |||
34 | /** |
||
35 | * Double/Float type |
||
36 | */ |
||
37 | const DOUBLE = Types::DOUBLE_TYPE; |
||
38 | |||
39 | /** |
||
40 | * Double/Float type |
||
41 | */ |
||
42 | const NUMBER = Types::NUMBER; |
||
43 | |||
44 | /** |
||
45 | * String type |
||
46 | */ |
||
47 | const STRING = Types::STRING_TYPE; |
||
48 | |||
49 | /** |
||
50 | * Boolean type |
||
51 | * true or false |
||
52 | */ |
||
53 | const BOOLEAN = Types::BOOLEAN_TYPE; |
||
54 | |||
55 | /** |
||
56 | * Array type |
||
57 | */ |
||
58 | const ARR = Types::ARRAY_TYPE; |
||
59 | |||
60 | /** |
||
61 | * Object type |
||
62 | */ |
||
63 | const OBJECT = Types::OBJECT_TYPE; |
||
64 | |||
65 | /** |
||
66 | * Resource handler type |
||
67 | */ |
||
68 | const RESOURCE = Types::RESOURCE_TYPE; |
||
69 | |||
70 | /** |
||
71 | * Callable type |
||
72 | */ |
||
73 | const CALLABLE_TYPE = Types::CALLABLE_TYPE; |
||
74 | |||
75 | /** |
||
76 | * Value is handled in variable |
||
77 | */ |
||
78 | const VARIABLE = 512; |
||
79 | |||
80 | /** |
||
81 | * NULL type |
||
82 | */ |
||
83 | const NULL = Types::NULL_TYPE; |
||
84 | |||
85 | /** |
||
86 | * self::INT_TYPE | self::DOUBLE_TYPE | self::STRING_TYPE | self::BOOLEAN_TYPE | self::ARRAY_TYPE | self::RESOURCE_TYPE | self::OBJECT_TYPE | self::NULL_TYPE |
||
87 | */ |
||
88 | const MIXED = Types::MIXED; |
||
89 | |||
90 | /** |
||
91 | * I can't explain what it's :D |
||
92 | */ |
||
93 | const DYNAMIC = 10000; |
||
94 | |||
95 | /** |
||
96 | * By default we don't know what it is |
||
97 | * |
||
98 | * @var int |
||
99 | */ |
||
100 | protected $type; |
||
101 | |||
102 | /** |
||
103 | * Possible value |
||
104 | * |
||
105 | * @var mixed |
||
106 | */ |
||
107 | protected $value; |
||
108 | |||
109 | /** |
||
110 | * @var Variable|null |
||
111 | */ |
||
112 | protected $variable; |
||
113 | |||
114 | /** |
||
115 | * Construct new CompiledExpression to pass result |
||
116 | * |
||
117 | * @param int $type |
||
118 | * @param mixed $value |
||
119 | * @param Variable|null $variable |
||
120 | */ |
||
121 | 764 | public function __construct($type = self::UNKNOWN, $value = null, Variable $variable = null) |
|
127 | |||
128 | /** |
||
129 | * Returns the value of the expression. |
||
130 | * |
||
131 | * @return mixed |
||
132 | */ |
||
133 | 744 | public function getValue() |
|
137 | |||
138 | /** |
||
139 | * Checks whether the expressions value equals the given value. |
||
140 | * |
||
141 | * @param integer $value |
||
142 | * @return boolean |
||
143 | */ |
||
144 | 72 | public function isEquals($value) |
|
148 | |||
149 | /** |
||
150 | * Returns the type of the expression. |
||
151 | * |
||
152 | * @return int |
||
153 | */ |
||
154 | 743 | public function getType() |
|
158 | |||
159 | /** |
||
160 | * Returns the type of the expression as a string. |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | 1 | public function getTypeName() |
|
165 | { |
||
166 | 1 | return CompilerTypes::getTypeName($this->type); |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Creates a variable from the expression. |
||
171 | * |
||
172 | * @param string $name Name of the Variable |
||
173 | * @return Variable |
||
174 | */ |
||
175 | 1 | public function toVariable($name) |
|
179 | |||
180 | /** |
||
181 | * If we don't know $type but know $value |
||
182 | * |
||
183 | * @param $value |
||
184 | * @throws RuntimeException |
||
185 | * @return CompiledExpression |
||
186 | */ |
||
187 | 405 | public static function fromZvalValue($value) |
|
188 | { |
||
189 | 405 | return new CompiledExpression(CompilerTypes::getTypeByValue($value), $value); |
|
190 | } |
||
191 | |||
192 | /** |
||
193 | * This is needed via in feature $this->type can store multiple type(s) by bitmask |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function canBeObject() |
||
198 | { |
||
199 | return (boolean) ($this->type == self::OBJECT || $this->type & self::OBJECT); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Returns debug info. |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | 4 | public function __debugInfo() |
|
214 | |||
215 | //@codeCoverageIgnoreStart |
||
216 | /** |
||
217 | * Check that $this->value is correct for $this->type |
||
218 | * |
||
219 | * @todo Implement it ;) |
||
220 | * @return boolean |
||
221 | */ |
||
222 | public function isCorrectValue() |
||
241 | //@codeCoverageIgnoreEnd |
||
242 | |||
243 | /** |
||
244 | * @return Variable|null |
||
245 | */ |
||
246 | public function getVariable() |
||
250 | |||
251 | /** |
||
252 | * @return bool |
||
253 | */ |
||
254 | 10 | public function isString() |
|
258 | |||
259 | /** |
||
260 | * @return bool |
||
261 | */ |
||
262 | 12 | public function isTypeKnown() |
|
266 | |||
267 | /** |
||
268 | * @return bool |
||
269 | */ |
||
270 | 23 | public function isScalar() |
|
274 | |||
275 | /** |
||
276 | * @return bool |
||
277 | */ |
||
278 | 3 | public function isArray() |
|
282 | |||
283 | /** |
||
284 | * @return bool |
||
285 | */ |
||
286 | public function isObject() |
||
290 | |||
291 | /** |
||
292 | * @return bool |
||
293 | */ |
||
294 | 10 | public function isCallable() |
|
298 | |||
299 | /** |
||
300 | * @return bool |
||
301 | */ |
||
302 | 5 | public function hasValue() |
|
306 | } |
||
307 |