@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | try |
101 | 101 | { |
102 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
102 | + if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
103 | 103 | eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
104 | 104 | |
105 | 105 | else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | return $line; |
260 | 260 | } |
261 | 261 | |
262 | - public static function clear (): void |
|
263 | - { |
|
264 | - self::$objects = []; |
|
265 | - self::$imported_styles = []; |
|
266 | - } |
|
262 | + public static function clear (): void |
|
263 | + { |
|
264 | + self::$objects = []; |
|
265 | + self::$imported_styles = []; |
|
266 | + } |
|
267 | 267 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @return array - возвращает список созданных объектов |
24 | 24 | */ |
25 | - public static function run (AST $tree, Node $parent = null): array |
|
25 | + public static function run(AST $tree, Node $parent = null): array |
|
26 | 26 | { |
27 | - foreach ($tree->getNodes () as $node) |
|
27 | + foreach ($tree->getNodes() as $node) |
|
28 | 28 | { |
29 | 29 | switch ($node->type) |
30 | 30 | { |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | $args = $node->args['args']; |
42 | 42 | |
43 | 43 | foreach ($args as $arg_id => $arg) |
44 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
44 | + $args[$arg_id] = self::formatLine($arg, self::$objects); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | try |
48 | 48 | { |
49 | - self::$objects[$name] = eval ("namespace VoidEngine; return new $class (". implode (', ', $args) .");"); |
|
49 | + self::$objects[$name] = eval ("namespace VoidEngine; return new $class (".implode(', ', $args).");"); |
|
50 | 50 | |
51 | 51 | try |
52 | 52 | { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | catch (\Throwable $e) |
60 | 60 | { |
61 | 61 | if (self::$throw_errors) |
62 | - throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
62 | + throw new \Exception('Interpeter couldn\'t create object "'.$class.'" with name "'.$name.'" at line "'.$node->line.'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
63 | 63 | } |
64 | 64 | break; |
65 | 65 | |
@@ -72,35 +72,35 @@ discard block |
||
72 | 72 | $propertyValue = $node->args['value']; |
73 | 73 | $preset = ''; |
74 | 74 | |
75 | - if (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
75 | + if (preg_match('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
76 | 76 | { |
77 | - $use = substr ($propertyValue, strpos ($propertyValue, 'use')); |
|
78 | - $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
|
79 | - $use = explode (' ', $use); |
|
77 | + $use = substr($propertyValue, strpos($propertyValue, 'use')); |
|
78 | + $use = $ouse = substr($use, ($pos = strpos($use, '(') + 1), strpos($use, ')') - $pos); |
|
79 | + $use = explode(' ', $use); |
|
80 | 80 | |
81 | 81 | foreach ($use as $id => $useParam) |
82 | 82 | if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
83 | 83 | { |
84 | 84 | $fname = $use[$id + 1]; |
85 | 85 | |
86 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
87 | - $fname = substr ($fname, 0, -1); |
|
86 | + if (substr($fname, strlen($fname) - 1) == ',') |
|
87 | + $fname = substr($fname, 0, -1); |
|
88 | 88 | |
89 | 89 | $preset .= "$fname = $useParam; "; |
90 | 90 | |
91 | 91 | unset ($use[$id]); |
92 | 92 | } |
93 | 93 | |
94 | - $preset = self::formatLine ($preset, self::$objects); |
|
95 | - $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
|
94 | + $preset = self::formatLine($preset, self::$objects); |
|
95 | + $propertyValue = self::formatLine(str_replace($ouse, implode(' ', $use), $propertyValue), self::$objects); |
|
96 | 96 | } |
97 | 97 | |
98 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
98 | + else $propertyValue = self::formatLine($propertyValue, self::$objects); |
|
99 | 99 | |
100 | 100 | try |
101 | 101 | { |
102 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
103 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
102 | + if (strpos($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
103 | + eval ('namespace VoidEngine; '.$preset.' _c('.self::$objects[$name]->selector.')->'.$propertyName.' = '.$propertyValue.';'); |
|
104 | 104 | |
105 | 105 | else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
106 | 106 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | catch (\Throwable $e) |
109 | 109 | { |
110 | 110 | if (self::$throw_errors) |
111 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
111 | + throw new \Exception('Interpeter couldn\'t set property "'.$propertyName.'" with value "'.$propertyValue.'" at line "'.$node->line.'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | elseif (self::$throw_errors) |
116 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
116 | + throw new \Exception('Setting property to an non-object at line "'.$node->line); |
|
117 | 117 | break; |
118 | 118 | |
119 | 119 | case METHOD_CALL: |
@@ -125,44 +125,44 @@ discard block |
||
125 | 125 | $methodArgs = $node->args['args']; |
126 | 126 | |
127 | 127 | foreach ($methodArgs as $arg_id => $arg) |
128 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
128 | + $methodArgs[$arg_id] = self::formatLine($arg, self::$objects); |
|
129 | 129 | |
130 | 130 | try |
131 | 131 | { |
132 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
133 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
132 | + if (strpos($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
133 | + eval ('namespace VoidEngine; _c('.self::$objects[$name]->selector.')->'.$methodName.' ('.implode(', ', $methodArgs).');'); |
|
134 | 134 | |
135 | - elseif (sizeof ($methodArgs) > 0) |
|
136 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
135 | + elseif (sizeof($methodArgs) > 0) |
|
136 | + self::$objects[$name]->$methodName(...eval ('namespace VoidEngine; return ['.implode(', ', $methodArgs).'];')); |
|
137 | 137 | |
138 | - else self::$objects[$name]->$methodName (); |
|
138 | + else self::$objects[$name]->$methodName(); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | catch (\Throwable $e) |
142 | 142 | { |
143 | 143 | if (self::$throw_errors) |
144 | - throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
144 | + throw new \Exception('Interpeter couldn\'t call method "'.$methodName.'" with arguments '.json_encode($methodArgs).' at line "'.$node->line.'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | elseif (self::$throw_errors) |
149 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
149 | + throw new \Exception('Calling method to an non-object at line "'.$node->line.'"'); |
|
150 | 150 | break; |
151 | 151 | |
152 | 152 | case STYLES_IMPORTING: |
153 | 153 | foreach ($node->args['imports'] as $style) |
154 | 154 | { |
155 | - $path = eval ('namespace VoidEngine; return '. self::formatLine ($style, self::$objects) .';'); |
|
155 | + $path = eval ('namespace VoidEngine; return '.self::formatLine($style, self::$objects).';'); |
|
156 | 156 | |
157 | - if (!file_exists ($path)) |
|
157 | + if (!file_exists($path)) |
|
158 | 158 | { |
159 | 159 | if (self::$throw_errors) |
160 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
160 | + throw new \Exception('Trying to import nonexistent style at line "'.$node->line.'"'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | elseif (!isset (self::$imported_styles[$path])) |
164 | 164 | { |
165 | - \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
|
165 | + \VLF\VST\Interpreter::run(\VLF\VST\Parser::parse(file_get_contents($path))); |
|
166 | 166 | |
167 | 167 | self::$imported_styles[$path] = true; |
168 | 168 | } |
@@ -170,28 +170,28 @@ discard block |
||
170 | 170 | break; |
171 | 171 | |
172 | 172 | case RUNTIME_EXECUTION: |
173 | - eval (self::formatLine ($node->args['code'], self::$objects)); |
|
173 | + eval (self::formatLine($node->args['code'], self::$objects)); |
|
174 | 174 | break; |
175 | 175 | } |
176 | 176 | |
177 | - $nodes = $node->getNodes (); |
|
177 | + $nodes = $node->getNodes(); |
|
178 | 178 | |
179 | 179 | if ($node->type == OBJECT_DEFINITION) |
180 | 180 | { |
181 | 181 | if (isset (\VLF\VST\Interpreter::$default_styles[$node->args['class']])) |
182 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
182 | + $nodes = array_merge($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
183 | 183 | |
184 | 184 | if (isset ($node->args['styles'])) |
185 | 185 | foreach ($node->args['styles'] as $style) |
186 | 186 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
187 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
187 | + $nodes = array_merge($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
188 | 188 | |
189 | 189 | elseif (self::$throw_errors) |
190 | - throw new \Exception ('Trying to set undefined style "'. $style .'" to object at line "'. $node->line .'"'); |
|
190 | + throw new \Exception('Trying to set undefined style "'.$style.'" to object at line "'.$node->line.'"'); |
|
191 | 191 | } |
192 | 192 | |
193 | - self::$objects = self::run (new AST (array_map ( |
|
194 | - fn ($node) => $node->export (), $nodes)), $node); |
|
193 | + self::$objects = self::run(new AST(array_map( |
|
194 | + fn($node) => $node->export(), $nodes)), $node); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return self::$objects; |
@@ -205,26 +205,25 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return string - возвращает форматированную строку |
207 | 207 | */ |
208 | - public static function formatLine (string $line, array $objects = []): string |
|
208 | + public static function formatLine(string $line, array $objects = []): string |
|
209 | 209 | { |
210 | - if (sizeof ($objects) > 0) |
|
210 | + if (sizeof($objects) > 0) |
|
211 | 211 | { |
212 | - $len = strlen ($line); |
|
212 | + $len = strlen($line); |
|
213 | 213 | $newLine = ''; |
214 | 214 | |
215 | - $replacement = array_map (function ($object) |
|
215 | + $replacement = array_map(function($object) |
|
216 | 216 | { |
217 | - return \VoidEngine\Components::exists ($object->selector) !== false ? |
|
218 | - '\VoidEngine\_c('. $object->selector .')' : |
|
219 | - 'unserialize (\''. serialize ($object) .'\')'; |
|
217 | + return \VoidEngine\Components::exists($object->selector) !== false ? |
|
218 | + '\VoidEngine\_c('.$object->selector.')' : 'unserialize (\''.serialize($object).'\')'; |
|
220 | 219 | }, $objects); |
221 | 220 | |
222 | - $replacement = array_map (function ($name) |
|
221 | + $replacement = array_map(function($name) |
|
223 | 222 | { |
224 | - return strlen ($name = trim ($name)) + substr_count ($name, '_'); |
|
225 | - }, $omap = array_flip ($replacement)); |
|
223 | + return strlen($name = trim($name)) + substr_count($name, '_'); |
|
224 | + }, $omap = array_flip($replacement)); |
|
226 | 225 | |
227 | - arsort ($replacement); |
|
226 | + arsort($replacement); |
|
228 | 227 | |
229 | 228 | $nReplacement = []; |
230 | 229 | |
@@ -232,14 +231,14 @@ discard block |
||
232 | 231 | $nReplacement[$omap[$replaceTo]] = $replaceTo; |
233 | 232 | |
234 | 233 | $replacement = $nReplacement; |
235 | - $blacklist = array_flip (['\'', '"', '$']); |
|
234 | + $blacklist = array_flip(['\'', '"', '$']); |
|
236 | 235 | |
237 | 236 | for ($i = 0; $i < $len; ++$i) |
238 | 237 | { |
239 | 238 | $replaced = false; |
240 | 239 | |
241 | 240 | foreach ($replacement as $name => $replaceAt) |
242 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
241 | + if (substr($line, $i, ($l = strlen($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
243 | 242 | { |
244 | 243 | $newLine .= $replaceAt; |
245 | 244 | |
@@ -259,7 +258,7 @@ discard block |
||
259 | 258 | return $line; |
260 | 259 | } |
261 | 260 | |
262 | - public static function clear (): void |
|
261 | + public static function clear(): void |
|
263 | 262 | { |
264 | 263 | self::$objects = []; |
265 | 264 | self::$imported_styles = []; |
@@ -61,9 +61,9 @@ |
||
61 | 61 | return [self::$styles, self::$default_styles]; |
62 | 62 | } |
63 | 63 | |
64 | - public static function clear (): void |
|
65 | - { |
|
66 | - self::$styles = []; |
|
67 | - self::$default_styles = []; |
|
68 | - } |
|
64 | + public static function clear (): void |
|
65 | + { |
|
66 | + self::$styles = []; |
|
67 | + self::$default_styles = []; |
|
68 | + } |
|
69 | 69 | } |
@@ -27,24 +27,24 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return array - возвращает список созданных стилей |
29 | 29 | */ |
30 | - public static function run (AST $tree, Node $parent = null): array |
|
30 | + public static function run(AST $tree, Node $parent = null): array |
|
31 | 31 | { |
32 | - foreach ($tree->getNodes () as $id => $node) |
|
32 | + foreach ($tree->getNodes() as $id => $node) |
|
33 | 33 | { |
34 | 34 | if ($node->type == \VLF\STYLE_DEFINITION) |
35 | 35 | { |
36 | 36 | $name = $node->args['name']; |
37 | - $nodes = $node->getNodes (); |
|
37 | + $nodes = $node->getNodes(); |
|
38 | 38 | |
39 | 39 | if ($node->args['parents'] !== null) |
40 | 40 | foreach ($node->args['parents'] as $parent) |
41 | 41 | if (!isset (self::$styles[$parent]) && !isset (self::$default_styles[$parent])) |
42 | 42 | { |
43 | 43 | if (self::$throw_errors) |
44 | - throw new \Exception ('Style "'. $parent .'" not founded'); |
|
44 | + throw new \Exception('Style "'.$parent.'" not founded'); |
|
45 | 45 | } |
46 | 46 | |
47 | - else $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
47 | + else $nodes = array_merge(self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
48 | 48 | |
49 | 49 | if ($node->args['is_default']) |
50 | 50 | self::$default_styles[$name] = isset (self::$objects[$name]) ? |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | array_merge (self::$styles[$name], $nodes) : $nodes; |
55 | 55 | } |
56 | 56 | |
57 | - list (self::$styles, self::$default_styles) = self::run (new AST (array_map ( |
|
58 | - fn ($node) => $node->export (), $node->getNodes ())), $node); |
|
57 | + list (self::$styles, self::$default_styles) = self::run(new AST(array_map( |
|
58 | + fn($node) => $node->export(), $node->getNodes())), $node); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return [self::$styles, self::$default_styles]; |
62 | 62 | } |
63 | 63 | |
64 | - public static function clear (): void |
|
64 | + public static function clear(): void |
|
65 | 65 | { |
66 | 66 | self::$styles = []; |
67 | 67 | self::$default_styles = []; |