@@ -10,19 +10,19 @@ |
||
10 | 10 | # Объявление констант |
11 | 11 | const APP_DIR = __DIR__; |
12 | 12 | |
13 | -define ('VoidEngine\CORE_DIR', dirname (__DIR__) .'/qero-packages/winforms-php/VoidFramework/core'); |
|
13 | +define('VoidEngine\CORE_DIR', dirname(__DIR__).'/qero-packages/winforms-php/VoidFramework/core'); |
|
14 | 14 | |
15 | 15 | # Подгружаем PHP расширения |
16 | -foreach (glob (CORE_DIR .'/ext/php_*.dll') as $ext) |
|
17 | - if (!extension_loaded (substr (basename ($ext), 4, -4))) |
|
18 | - load_extension ($ext); |
|
16 | +foreach (glob(CORE_DIR.'/ext/php_*.dll') as $ext) |
|
17 | + if (!extension_loaded(substr(basename($ext), 4, -4))) |
|
18 | + load_extension($ext); |
|
19 | 19 | |
20 | 20 | # Подгружаем Qero-пакеты |
21 | -require __DIR__ .'/../qero-packages/autoload.php'; |
|
21 | +require __DIR__.'/../qero-packages/autoload.php'; |
|
22 | 22 | |
23 | -chdir (APP_DIR); // Меняем стандартную директорию на директорию приложения |
|
23 | +chdir(APP_DIR); // Меняем стандартную директорию на директорию приложения |
|
24 | 24 | |
25 | 25 | # Парсим разметку app.vlf и запускаем приложение |
26 | -$objects = Interpreter::run (Parser::parse ('app.vlf')); |
|
26 | +$objects = Interpreter::run(Parser::parse('app.vlf')); |
|
27 | 27 | |
28 | -$APPLICATION->run ($objects['MainForm']); |
|
28 | +$APPLICATION->run($objects['MainForm']); |
@@ -20,33 +20,33 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return AST - возвращает AST дерево разметки |
22 | 22 | */ |
23 | - public static function parse (string $vst): AST |
|
23 | + public static function parse(string $vst): AST |
|
24 | 24 | { |
25 | 25 | $tree = new AST; |
26 | 26 | $objects = new Stack; |
27 | 27 | |
28 | - if (file_exists ($vst)) |
|
29 | - $vst = file_get_contents ($vst); |
|
28 | + if (file_exists($vst)) |
|
29 | + $vst = file_get_contents($vst); |
|
30 | 30 | |
31 | - $lines = explode (self::$divider, $vst); |
|
31 | + $lines = explode(self::$divider, $vst); |
|
32 | 32 | $skip_at = -1; |
33 | 33 | |
34 | 34 | foreach ($lines as $line_num => $line) |
35 | 35 | { |
36 | 36 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
37 | 37 | |
38 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
38 | + if ($skip_at > $line_num || !self::filter($line)) |
|
39 | 39 | continue; |
40 | 40 | |
41 | - $height = self::getHeight ($line); |
|
42 | - $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
|
41 | + $height = self::getHeight($line); |
|
42 | + $words = array_filter(explode(' ', $line), 'VLF\Parser::filter'); |
|
43 | 43 | $poped = false; |
44 | 44 | |
45 | 45 | # Очищаем стек объектов |
46 | - while ($objects->size () > 0) |
|
47 | - if ($objects->current ()->height >= $height) |
|
46 | + while ($objects->size() > 0) |
|
47 | + if ($objects->current()->height >= $height) |
|
48 | 48 | { |
49 | - $objects->pop (); |
|
49 | + $objects->pop(); |
|
50 | 50 | |
51 | 51 | $poped = true; |
52 | 52 | } |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | else break; |
55 | 55 | |
56 | 56 | # Создаём новую ссылку на объект |
57 | - if ($poped && $objects->size () > 0) |
|
57 | + if ($poped && $objects->size() > 0) |
|
58 | 58 | { |
59 | - $object = $objects->pop (); |
|
59 | + $object = $objects->pop(); |
|
60 | 60 | |
61 | - $objects->push (new Node (array_merge ($object->export (), ['nodes' => []]))); |
|
62 | - $tree->push ($objects->current ()); |
|
61 | + $objects->push(new Node(array_merge($object->export(), ['nodes' => []]))); |
|
62 | + $tree->push($objects->current()); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | if (isset ($words[0][1])) |
74 | 74 | { |
75 | 75 | if ($words[0][1] == '^') |
76 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
76 | + $skip_at = self::parseSubtext($lines, $line_num, $height)[1]; |
|
77 | 77 | |
78 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
78 | + else throw new \Exception('Unknown char founded after comment definition at line '.($line_num + 1)); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | continue; |
@@ -86,30 +86,30 @@ discard block |
||
86 | 86 | */ |
87 | 87 | elseif ($words[0][0] == '.') |
88 | 88 | { |
89 | - $pos = strpos ($line, ':'); |
|
89 | + $pos = strpos($line, ':'); |
|
90 | 90 | $parents = null; |
91 | 91 | |
92 | 92 | if ($pos !== false) |
93 | 93 | { |
94 | - $name = trim (substr ($line, 1, $pos - 1)); |
|
94 | + $name = trim(substr($line, 1, $pos - 1)); |
|
95 | 95 | |
96 | 96 | if (isset ($line[$pos])) |
97 | 97 | { |
98 | - $parents = trim (substr ($line, $pos + 1)); |
|
98 | + $parents = trim(substr($line, $pos + 1)); |
|
99 | 99 | |
100 | - if (strlen ($parents) == 0) |
|
100 | + if (strlen($parents) == 0) |
|
101 | 101 | $parents = null; |
102 | 102 | |
103 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
103 | + else $parents = array_map('trim', explode(',', $parents)); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - else $name = trim (substr ($line, 1)); |
|
107 | + else $name = trim(substr($line, 1)); |
|
108 | 108 | |
109 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
110 | - $parents = [$objects->current ()->args['name']]; |
|
109 | + if ($parents === null && $objects->size() > 0 && $objects->current()->height < $height) |
|
110 | + $parents = [$objects->current()->args['name']]; |
|
111 | 111 | |
112 | - $objects->push (new Node ([ |
|
112 | + $objects->push(new Node([ |
|
113 | 113 | 'type' => \VLF\STYLE_DEFINITION, |
114 | 114 | 'line' => $line, |
115 | 115 | 'words' => $words, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ] |
123 | 123 | ])); |
124 | 124 | |
125 | - $tree->push ($objects->current ()); |
|
125 | + $tree->push($objects->current()); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,30 +130,30 @@ discard block |
||
130 | 130 | */ |
131 | 131 | elseif ($words[0][0] == '*') |
132 | 132 | { |
133 | - $pos = strpos ($line, ':'); |
|
133 | + $pos = strpos($line, ':'); |
|
134 | 134 | $parents = null; |
135 | 135 | |
136 | 136 | if ($pos !== false) |
137 | 137 | { |
138 | - $name = trim (substr ($line, 1, $pos - 1)); |
|
138 | + $name = trim(substr($line, 1, $pos - 1)); |
|
139 | 139 | |
140 | 140 | if (isset ($line[$pos])) |
141 | 141 | { |
142 | - $parents = trim (substr ($line, $pos + 1)); |
|
142 | + $parents = trim(substr($line, $pos + 1)); |
|
143 | 143 | |
144 | - if (strlen ($parents) == 0) |
|
144 | + if (strlen($parents) == 0) |
|
145 | 145 | $parents = null; |
146 | 146 | |
147 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
147 | + else $parents = array_map('trim', explode(',', $parents)); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - else $name = trim (substr ($line, 1)); |
|
151 | + else $name = trim(substr($line, 1)); |
|
152 | 152 | |
153 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
154 | - $parents = [$objects->current ()->args['name']]; |
|
153 | + if ($parents === null && $objects->size() > 0 && $objects->current()->height < $height) |
|
154 | + $parents = [$objects->current()->args['name']]; |
|
155 | 155 | |
156 | - $objects->push (new Node ([ |
|
156 | + $objects->push(new Node([ |
|
157 | 157 | 'type' => \VLF\STYLE_DEFINITION, |
158 | 158 | 'line' => $line, |
159 | 159 | 'words' => $words, |
@@ -166,35 +166,35 @@ discard block |
||
166 | 166 | ] |
167 | 167 | ])); |
168 | 168 | |
169 | - $tree->push ($objects->current ()); |
|
169 | + $tree->push($objects->current()); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Установка свойства |
174 | 174 | */ |
175 | - elseif (($pos = strpos ($line, ':')) !== false) |
|
175 | + elseif (($pos = strpos($line, ':')) !== false) |
|
176 | 176 | { |
177 | - if ($objects->size () == 0) |
|
178 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
177 | + if ($objects->size() == 0) |
|
178 | + throw new \Exception('Trying to set property to unknown object at line '.($line_num + 1)); |
|
179 | 179 | |
180 | 180 | if (!isset ($words[1])) |
181 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
181 | + throw new \Exception('Trying to set void property value at line '.($line_num + 1)); |
|
182 | 182 | |
183 | - $propertyName = substr ($line, 0, $pos); |
|
184 | - $propertyValue = substr ($line, $pos + 1); |
|
183 | + $propertyName = substr($line, 0, $pos); |
|
184 | + $propertyValue = substr($line, $pos + 1); |
|
185 | 185 | |
186 | 186 | /** |
187 | 187 | * Обработка многострочных свойств |
188 | 188 | */ |
189 | 189 | if ($line[$pos + 1] == '^') |
190 | 190 | { |
191 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
191 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
192 | 192 | |
193 | - $propertyValue = substr ($propertyValue, 1) . $parsed[0]; |
|
193 | + $propertyValue = substr($propertyValue, 1).$parsed[0]; |
|
194 | 194 | $skip_at = $parsed[1]; |
195 | 195 | } |
196 | 196 | |
197 | - $objects->current ()->push (new Node ([ |
|
197 | + $objects->current()->push(new Node([ |
|
198 | 198 | 'type' => \VLF\PROPERTY_SET, |
199 | 199 | 'line' => $line, |
200 | 200 | 'words' => $words, |
@@ -212,26 +212,26 @@ discard block |
||
212 | 212 | */ |
213 | 213 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
214 | 214 | { |
215 | - if ($objects->size () == 0) |
|
216 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
215 | + if ($objects->size() == 0) |
|
216 | + throw new \Exception('Trying to call method from unknown object at line '.($line_num + 1)); |
|
217 | 217 | |
218 | 218 | $methodArgs = []; |
219 | 219 | |
220 | - if (($pos = strpos ($line, '(')) !== false) |
|
220 | + if (($pos = strpos($line, '(')) !== false) |
|
221 | 221 | { |
222 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
223 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
222 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
223 | + throw new \Exception('Incorrect method arguments syntax at line '.($line_num + 1)); |
|
224 | 224 | |
225 | - $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
|
225 | + $methodArgs = substr($line, $pos + 1, $end - $pos - 1); |
|
226 | 226 | |
227 | - $methodName = trim (substr ($line, 2, $pos - 2)); |
|
228 | - $methodArgs = self::filter ($methodArgs) ? |
|
229 | - self::parseArguments ($methodArgs) : []; |
|
227 | + $methodName = trim(substr($line, 2, $pos - 2)); |
|
228 | + $methodArgs = self::filter($methodArgs) ? |
|
229 | + self::parseArguments($methodArgs) : []; |
|
230 | 230 | } |
231 | 231 | |
232 | - else $methodName = trim (substr ($line, 2)); |
|
232 | + else $methodName = trim(substr($line, 2)); |
|
233 | 233 | |
234 | - $objects->current ()->push (new Node ([ |
|
234 | + $objects->current()->push(new Node([ |
|
235 | 235 | 'type' => \VLF\METHOD_CALL, |
236 | 236 | 'line' => $line, |
237 | 237 | 'words' => $words, |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | /** |
248 | 248 | * Неопознанная структура |
249 | 249 | */ |
250 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
250 | + else throw new \Exception('Unsupported structure founded at line '.($line_num + 1)); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | return $tree; |
@@ -25,8 +25,9 @@ discard block |
||
25 | 25 | $tree = new AST; |
26 | 26 | $objects = new Stack; |
27 | 27 | |
28 | - if (file_exists ($vst)) |
|
29 | - $vst = file_get_contents ($vst); |
|
28 | + if (file_exists ($vst)) { |
|
29 | + $vst = file_get_contents ($vst); |
|
30 | + } |
|
30 | 31 | |
31 | 32 | $lines = explode (self::$divider, $vst); |
32 | 33 | $skip_at = -1; |
@@ -35,24 +36,26 @@ discard block |
||
35 | 36 | { |
36 | 37 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
37 | 38 | |
38 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
39 | - continue; |
|
39 | + if ($skip_at > $line_num || !self::filter ($line)) { |
|
40 | + continue; |
|
41 | + } |
|
40 | 42 | |
41 | 43 | $height = self::getHeight ($line); |
42 | 44 | $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
43 | 45 | $poped = false; |
44 | 46 | |
45 | 47 | # Очищаем стек объектов |
46 | - while ($objects->size () > 0) |
|
47 | - if ($objects->current ()->height >= $height) |
|
48 | + while ($objects->size () > 0) { |
|
49 | + if ($objects->current ()->height >= $height) |
|
48 | 50 | { |
49 | 51 | $objects->pop (); |
52 | + } |
|
50 | 53 | |
51 | 54 | $poped = true; |
55 | + } else { |
|
56 | + break; |
|
52 | 57 | } |
53 | 58 | |
54 | - else break; |
|
55 | - |
|
56 | 59 | # Создаём новую ссылку на объект |
57 | 60 | if ($poped && $objects->size () > 0) |
58 | 61 | { |
@@ -72,10 +75,11 @@ discard block |
||
72 | 75 | */ |
73 | 76 | if (isset ($words[0][1])) |
74 | 77 | { |
75 | - if ($words[0][1] == '^') |
|
76 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
77 | - |
|
78 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
78 | + if ($words[0][1] == '^') { |
|
79 | + $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
80 | + } else { |
|
81 | + throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
82 | + } |
|
79 | 83 | } |
80 | 84 | |
81 | 85 | continue; |
@@ -97,17 +101,19 @@ discard block |
||
97 | 101 | { |
98 | 102 | $parents = trim (substr ($line, $pos + 1)); |
99 | 103 | |
100 | - if (strlen ($parents) == 0) |
|
101 | - $parents = null; |
|
102 | - |
|
103 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
104 | + if (strlen ($parents) == 0) { |
|
105 | + $parents = null; |
|
106 | + } else { |
|
107 | + $parents = array_map ('trim', explode (',', $parents)); |
|
108 | + } |
|
104 | 109 | } |
110 | + } else { |
|
111 | + $name = trim (substr ($line, 1)); |
|
105 | 112 | } |
106 | 113 | |
107 | - else $name = trim (substr ($line, 1)); |
|
108 | - |
|
109 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
110 | - $parents = [$objects->current ()->args['name']]; |
|
114 | + if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) { |
|
115 | + $parents = [$objects->current ()->args['name']]; |
|
116 | + } |
|
111 | 117 | |
112 | 118 | $objects->push (new Node ([ |
113 | 119 | 'type' => \VLF\STYLE_DEFINITION, |
@@ -141,17 +147,19 @@ discard block |
||
141 | 147 | { |
142 | 148 | $parents = trim (substr ($line, $pos + 1)); |
143 | 149 | |
144 | - if (strlen ($parents) == 0) |
|
145 | - $parents = null; |
|
146 | - |
|
147 | - else $parents = array_map ('trim', explode (',', $parents)); |
|
150 | + if (strlen ($parents) == 0) { |
|
151 | + $parents = null; |
|
152 | + } else { |
|
153 | + $parents = array_map ('trim', explode (',', $parents)); |
|
154 | + } |
|
148 | 155 | } |
156 | + } else { |
|
157 | + $name = trim (substr ($line, 1)); |
|
149 | 158 | } |
150 | 159 | |
151 | - else $name = trim (substr ($line, 1)); |
|
152 | - |
|
153 | - if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) |
|
154 | - $parents = [$objects->current ()->args['name']]; |
|
160 | + if ($parents === null && $objects->size () > 0 && $objects->current ()->height < $height) { |
|
161 | + $parents = [$objects->current ()->args['name']]; |
|
162 | + } |
|
155 | 163 | |
156 | 164 | $objects->push (new Node ([ |
157 | 165 | 'type' => \VLF\STYLE_DEFINITION, |
@@ -174,11 +182,13 @@ discard block |
||
174 | 182 | */ |
175 | 183 | elseif (($pos = strpos ($line, ':')) !== false) |
176 | 184 | { |
177 | - if ($objects->size () == 0) |
|
178 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
185 | + if ($objects->size () == 0) { |
|
186 | + throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
187 | + } |
|
179 | 188 | |
180 | - if (!isset ($words[1])) |
|
181 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
189 | + if (!isset ($words[1])) { |
|
190 | + throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
191 | + } |
|
182 | 192 | |
183 | 193 | $propertyName = substr ($line, 0, $pos); |
184 | 194 | $propertyValue = substr ($line, $pos + 1); |
@@ -212,25 +222,27 @@ discard block |
||
212 | 222 | */ |
213 | 223 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
214 | 224 | { |
215 | - if ($objects->size () == 0) |
|
216 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
225 | + if ($objects->size () == 0) { |
|
226 | + throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
227 | + } |
|
217 | 228 | |
218 | 229 | $methodArgs = []; |
219 | 230 | |
220 | 231 | if (($pos = strpos ($line, '(')) !== false) |
221 | 232 | { |
222 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
223 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
233 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
234 | + throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
235 | + } |
|
224 | 236 | |
225 | 237 | $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
226 | 238 | |
227 | 239 | $methodName = trim (substr ($line, 2, $pos - 2)); |
228 | 240 | $methodArgs = self::filter ($methodArgs) ? |
229 | 241 | self::parseArguments ($methodArgs) : []; |
242 | + } else { |
|
243 | + $methodName = trim (substr ($line, 2)); |
|
230 | 244 | } |
231 | 245 | |
232 | - else $methodName = trim (substr ($line, 2)); |
|
233 | - |
|
234 | 246 | $objects->current ()->push (new Node ([ |
235 | 247 | 'type' => \VLF\METHOD_CALL, |
236 | 248 | 'line' => $line, |
@@ -247,7 +259,9 @@ discard block |
||
247 | 259 | /** |
248 | 260 | * Неопознанная структура |
249 | 261 | */ |
250 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
262 | + else { |
|
263 | + throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
264 | + } |
|
251 | 265 | } |
252 | 266 | |
253 | 267 | return $tree; |
@@ -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,8 +54,8 @@ 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]; |
@@ -36,22 +36,24 @@ |
||
36 | 36 | $name = $node->args['name']; |
37 | 37 | $nodes = $node->getNodes (); |
38 | 38 | |
39 | - if ($node->args['parents'] !== null) |
|
40 | - foreach ($node->args['parents'] as $parent) |
|
39 | + if ($node->args['parents'] !== null) { |
|
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 | 44 | throw new \Exception ('Style "'. $parent .'" not founded'); |
45 | + } |
|
46 | + } else { |
|
47 | + $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
45 | 48 | } |
46 | 49 | |
47 | - else $nodes = array_merge (self::$styles[$parent] ?? self::$default_styles[$parent], $nodes); |
|
48 | - |
|
49 | - if ($node->args['is_default']) |
|
50 | - self::$default_styles[$name] = isset (self::$objects[$name]) ? |
|
50 | + if ($node->args['is_default']) { |
|
51 | + self::$default_styles[$name] = isset (self::$objects[$name]) ? |
|
51 | 52 | array_merge (self::$default_styles[$name], $nodes) : $nodes; |
52 | - |
|
53 | - else self::$styles[$name] = isset (self::$objects[$name]) ? |
|
53 | + } else { |
|
54 | + self::$styles[$name] = isset (self::$objects[$name]) ? |
|
54 | 55 | array_merge (self::$styles[$name], $nodes) : $nodes; |
56 | + } |
|
55 | 57 | } |
56 | 58 | |
57 | 59 | list (self::$styles, self::$default_styles) = self::run (new AST (array_map ( |
@@ -17,33 +17,33 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return AST - возвращает AST дерево разметки |
19 | 19 | */ |
20 | - public static function parse (string $vlf): AST |
|
20 | + public static function parse(string $vlf): AST |
|
21 | 21 | { |
22 | 22 | $tree = new AST; |
23 | 23 | $objects = new Stack; |
24 | 24 | |
25 | - if (file_exists ($vlf)) |
|
26 | - $vlf = file_get_contents ($vlf); |
|
25 | + if (file_exists($vlf)) |
|
26 | + $vlf = file_get_contents($vlf); |
|
27 | 27 | |
28 | - $lines = explode (self::$divider, $vlf); |
|
28 | + $lines = explode(self::$divider, $vlf); |
|
29 | 29 | $skip_at = -1; |
30 | 30 | |
31 | 31 | foreach ($lines as $line_num => $line) |
32 | 32 | { |
33 | 33 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
34 | 34 | |
35 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
35 | + if ($skip_at > $line_num || !self::filter($line)) |
|
36 | 36 | continue; |
37 | 37 | |
38 | - $height = self::getHeight ($line); |
|
39 | - $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
|
38 | + $height = self::getHeight($line); |
|
39 | + $words = array_filter(explode(' ', $line), 'VLF\Parser::filter'); |
|
40 | 40 | $poped = false; |
41 | 41 | |
42 | 42 | # Очищаем стек объектов |
43 | - while ($objects->size () > 0) |
|
44 | - if ($objects->current ()->height >= $height) |
|
43 | + while ($objects->size() > 0) |
|
44 | + if ($objects->current()->height >= $height) |
|
45 | 45 | { |
46 | - $objects->pop (); |
|
46 | + $objects->pop(); |
|
47 | 47 | |
48 | 48 | $poped = true; |
49 | 49 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | else break; |
52 | 52 | |
53 | 53 | # Создаём новую ссылку на объект |
54 | - if ($poped && $objects->size () > 0) |
|
54 | + if ($poped && $objects->size() > 0) |
|
55 | 55 | { |
56 | - $object = $objects->pop (); |
|
56 | + $object = $objects->pop(); |
|
57 | 57 | |
58 | - $objects->push (new Node (array_merge ($object->export (), ['nodes' => []]))); |
|
59 | - $tree->push ($objects->current ()); |
|
58 | + $objects->push(new Node(array_merge($object->export(), ['nodes' => []]))); |
|
59 | + $tree->push($objects->current()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,16 +64,16 @@ discard block |
||
64 | 64 | */ |
65 | 65 | if ($words[0] == 'import') |
66 | 66 | { |
67 | - $imports = substr ($line, strlen ($words[0])); |
|
68 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
67 | + $imports = substr($line, strlen($words[0])); |
|
68 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
69 | 69 | |
70 | 70 | $imports .= $parsed[0]; |
71 | 71 | $skip_at = $parsed[1]; |
72 | 72 | |
73 | - $imports = self::filter ($imports) ? |
|
74 | - array_map ('trim', self::parseArguments ($imports)) : []; |
|
73 | + $imports = self::filter($imports) ? |
|
74 | + array_map ('trim', self::parseArguments($imports)) : []; |
|
75 | 75 | |
76 | - $tree->push (new Node ([ |
|
76 | + $tree->push(new Node([ |
|
77 | 77 | 'type' => STYLES_IMPORTING, |
78 | 78 | 'line' => $line, |
79 | 79 | 'words' => $words, |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | if (isset ($words[0][1])) |
97 | 97 | { |
98 | 98 | if ($words[0][1] == '^') |
99 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
99 | + $skip_at = self::parseSubtext($lines, $line_num, $height)[1]; |
|
100 | 100 | |
101 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
101 | + else throw new \Exception('Unknown char founded after comment definition at line '.($line_num + 1)); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | continue; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | elseif ($words[0][0] == '%') |
111 | 111 | { |
112 | - $code = substr ($line, strlen ($words[0])); |
|
112 | + $code = substr($line, strlen($words[0])); |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Обработка многострочного кода |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | { |
119 | 119 | if ($words[0][1] == '^') |
120 | 120 | { |
121 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
121 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
122 | 122 | |
123 | 123 | $code .= $parsed[0]; |
124 | 124 | $skip_at = $parsed[1]; |
125 | 125 | } |
126 | 126 | |
127 | - else throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
127 | + else throw new \Exception('Unknown char founded after runtime execution definition at line '.($line_num + 1)); |
|
128 | 128 | } |
129 | 129 | |
130 | - $tree->push (new Node ([ |
|
130 | + $tree->push(new Node([ |
|
131 | 131 | 'type' => RUNTIME_EXECUTION, |
132 | 132 | 'line' => $line, |
133 | 133 | 'words' => $words, |
@@ -142,29 +142,29 @@ discard block |
||
142 | 142 | /** |
143 | 143 | * Установка свойства |
144 | 144 | */ |
145 | - elseif (($pos = strpos ($line, ':')) !== false) |
|
145 | + elseif (($pos = strpos($line, ':')) !== false) |
|
146 | 146 | { |
147 | - if ($objects->size () == 0) |
|
148 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
147 | + if ($objects->size() == 0) |
|
148 | + throw new \Exception('Trying to set property to unknown object at line '.($line_num + 1)); |
|
149 | 149 | |
150 | 150 | if (!isset ($words[1])) |
151 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
151 | + throw new \Exception('Trying to set void property value at line '.($line_num + 1)); |
|
152 | 152 | |
153 | - $propertyName = substr ($line, 0, $pos); |
|
154 | - $propertyValue = substr ($line, $pos + 1); |
|
153 | + $propertyName = substr($line, 0, $pos); |
|
154 | + $propertyValue = substr($line, $pos + 1); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Обработка многострочных свойств |
158 | 158 | */ |
159 | 159 | if ($line[$pos + 1] == '^') |
160 | 160 | { |
161 | - $parsed = self::parseSubtext ($lines, $line_num, $height); |
|
161 | + $parsed = self::parseSubtext($lines, $line_num, $height); |
|
162 | 162 | |
163 | - $propertyValue = substr ($propertyValue, 1) . $parsed[0]; |
|
163 | + $propertyValue = substr($propertyValue, 1).$parsed[0]; |
|
164 | 164 | $skip_at = $parsed[1]; |
165 | 165 | } |
166 | 166 | |
167 | - $objects->current ()->push (new Node ([ |
|
167 | + $objects->current()->push(new Node([ |
|
168 | 168 | 'type' => PROPERTY_SET, |
169 | 169 | 'line' => $line, |
170 | 170 | 'words' => $words, |
@@ -182,26 +182,26 @@ discard block |
||
182 | 182 | */ |
183 | 183 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
184 | 184 | { |
185 | - if ($objects->size () == 0) |
|
186 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
185 | + if ($objects->size() == 0) |
|
186 | + throw new \Exception('Trying to call method from unknown object at line '.($line_num + 1)); |
|
187 | 187 | |
188 | 188 | $methodArgs = []; |
189 | 189 | |
190 | - if (($pos = strpos ($line, '(')) !== false) |
|
190 | + if (($pos = strpos($line, '(')) !== false) |
|
191 | 191 | { |
192 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
193 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
192 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
193 | + throw new \Exception('Incorrect method arguments syntax at line '.($line_num + 1)); |
|
194 | 194 | |
195 | - $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
|
195 | + $methodArgs = substr($line, $pos + 1, $end - $pos - 1); |
|
196 | 196 | |
197 | - $methodName = trim (substr ($line, 2, $pos - 2)); |
|
198 | - $methodArgs = self::filter ($methodArgs) ? |
|
199 | - self::parseArguments ($methodArgs) : []; |
|
197 | + $methodName = trim(substr($line, 2, $pos - 2)); |
|
198 | + $methodArgs = self::filter($methodArgs) ? |
|
199 | + self::parseArguments($methodArgs) : []; |
|
200 | 200 | } |
201 | 201 | |
202 | - else $methodName = trim (substr ($line, 2)); |
|
202 | + else $methodName = trim(substr($line, 2)); |
|
203 | 203 | |
204 | - $objects->current ()->push (new Node ([ |
|
204 | + $objects->current()->push(new Node([ |
|
205 | 205 | 'type' => METHOD_CALL, |
206 | 206 | 'line' => $line, |
207 | 207 | 'words' => $words, |
@@ -217,39 +217,39 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * Объявление объекта |
219 | 219 | */ |
220 | - elseif (sizeof ($words) > 1) |
|
220 | + elseif (sizeof($words) > 1) |
|
221 | 221 | { |
222 | 222 | $class = $words[0]; |
223 | 223 | $name = $words[1]; |
224 | 224 | $args = []; |
225 | 225 | $styles = []; |
226 | 226 | |
227 | - if ($objects->size () > 0 && $objects->current ()->height < $height) |
|
228 | - $args[] = $objects->current ()->args['name']; |
|
227 | + if ($objects->size() > 0 && $objects->current()->height < $height) |
|
228 | + $args[] = $objects->current()->args['name']; |
|
229 | 229 | |
230 | - if (($pos = strpos ($line, '(')) !== false) |
|
230 | + if (($pos = strpos($line, '(')) !== false) |
|
231 | 231 | { |
232 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
233 | - throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
232 | + if (($end = strrpos($line, ')', $pos)) === false) |
|
233 | + throw new \Exception('Incorrect class constructor arguments syntax at line '.($line_num + 1)); |
|
234 | 234 | |
235 | - $args = substr ($line, $pos + 1, $end - $pos - 1); |
|
235 | + $args = substr($line, $pos + 1, $end - $pos - 1); |
|
236 | 236 | |
237 | - $name = substr ($line, $len = strlen ($class), $pos - $len); |
|
238 | - $args = self::filter ($args) ? |
|
239 | - self::parseArguments ($args) : []; |
|
237 | + $name = substr($line, $len = strlen($class), $pos - $len); |
|
238 | + $args = self::filter($args) ? |
|
239 | + self::parseArguments($args) : []; |
|
240 | 240 | } |
241 | 241 | |
242 | - if (($end = strrpos ($line, ' > ')) !== false) |
|
242 | + if (($end = strrpos($line, ' > ')) !== false) |
|
243 | 243 | { |
244 | - $styles = trim (substr ($line, $end + 3)); |
|
244 | + $styles = trim(substr($line, $end + 3)); |
|
245 | 245 | |
246 | - if (strlen ($styles) == 0) |
|
247 | - throw new \Exception ('Trying to set empty style to object'); |
|
246 | + if (strlen($styles) == 0) |
|
247 | + throw new \Exception('Trying to set empty style to object'); |
|
248 | 248 | |
249 | - $styles = array_map ('trim', explode (',', $styles)); |
|
249 | + $styles = array_map('trim', explode(',', $styles)); |
|
250 | 250 | } |
251 | 251 | |
252 | - $objects->push (new Node ([ |
|
252 | + $objects->push(new Node([ |
|
253 | 253 | 'type' => OBJECT_DEFINITION, |
254 | 254 | 'line' => $line, |
255 | 255 | 'words' => $words, |
@@ -257,19 +257,19 @@ discard block |
||
257 | 257 | |
258 | 258 | 'args' => [ |
259 | 259 | 'class' => $class, |
260 | - 'name' => trim ($name), |
|
260 | + 'name' => trim($name), |
|
261 | 261 | 'args' => $args, |
262 | 262 | 'styles' => $styles |
263 | 263 | ] |
264 | 264 | ])); |
265 | 265 | |
266 | - $tree->push ($objects->current ()); |
|
266 | + $tree->push($objects->current()); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
270 | 270 | * Неопознанная структура |
271 | 271 | */ |
272 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
272 | + else throw new \Exception('Unsupported structure founded at line '.($line_num + 1)); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | return $tree; |
@@ -282,12 +282,12 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return int - возвращает её высоту |
284 | 284 | */ |
285 | - protected static function getHeight (string &$line): int |
|
285 | + protected static function getHeight(string &$line): int |
|
286 | 286 | { |
287 | 287 | $i = 0; |
288 | 288 | $height = 0; |
289 | 289 | |
290 | - while (isset ($line[$i]) && ctype_space ($line[$i])) |
|
290 | + while (isset ($line[$i]) && ctype_space($line[$i])) |
|
291 | 291 | { |
292 | 292 | ++$height; |
293 | 293 | |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | ++$i; |
298 | 298 | } |
299 | 299 | |
300 | - $line = substr ($line, $i); |
|
300 | + $line = substr($line, $i); |
|
301 | 301 | |
302 | 302 | return $height; |
303 | 303 | } |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return bool - возвращает true если строка не пустая |
311 | 311 | */ |
312 | - protected static function filter (string $line): bool |
|
312 | + protected static function filter(string $line): bool |
|
313 | 313 | { |
314 | - return strlen (trim ($line)) > 0; |
|
314 | + return strlen(trim($line)) > 0; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @return array - возвращает массив [текст, конечный индекс] |
325 | 325 | */ |
326 | - protected static function parseSubtext (array $lines, $begin_id, int $down_height): array |
|
326 | + protected static function parseSubtext(array $lines, $begin_id, int $down_height): array |
|
327 | 327 | { |
328 | 328 | $parsed = "\n"; |
329 | 329 | |
@@ -332,17 +332,17 @@ discard block |
||
332 | 332 | if ($line_id <= $begin_id) |
333 | 333 | continue; |
334 | 334 | |
335 | - if (!self::filter ($line)) |
|
335 | + if (!self::filter($line)) |
|
336 | 336 | { |
337 | 337 | $parsed .= "\n"; |
338 | 338 | |
339 | 339 | continue; |
340 | 340 | } |
341 | 341 | |
342 | - $height = self::getHeight ($line); |
|
342 | + $height = self::getHeight($line); |
|
343 | 343 | |
344 | 344 | if ($height > $down_height) |
345 | - $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
345 | + $parsed .= str_repeat(' ', $height - $down_height)."$line\n"; |
|
346 | 346 | |
347 | 347 | else return [$parsed, $line_id]; |
348 | 348 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * |
358 | 358 | * @return array - возвращает массив аргументов |
359 | 359 | */ |
360 | - protected static function parseArguments (string $arguments): array |
|
360 | + protected static function parseArguments(string $arguments): array |
|
361 | 361 | { |
362 | 362 | $args = []; |
363 | 363 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | $t = ''; |
368 | 368 | |
369 | - for ($i = 0, $len = strlen ($arguments); $i < $len; ++$i) |
|
369 | + for ($i = 0, $len = strlen($arguments); $i < $len; ++$i) |
|
370 | 370 | { |
371 | 371 | $t .= $arguments[$i]; |
372 | 372 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | |
384 | 384 | elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
385 | 385 | { |
386 | - $args[] = substr ($t, 0, -1); |
|
386 | + $args[] = substr($t, 0, -1); |
|
387 | 387 | $t = ''; |
388 | 388 | } |
389 | 389 | } |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | $tree = new AST; |
23 | 23 | $objects = new Stack; |
24 | 24 | |
25 | - if (file_exists ($vlf)) |
|
26 | - $vlf = file_get_contents ($vlf); |
|
25 | + if (file_exists ($vlf)) { |
|
26 | + $vlf = file_get_contents ($vlf); |
|
27 | + } |
|
27 | 28 | |
28 | 29 | $lines = explode (self::$divider, $vlf); |
29 | 30 | $skip_at = -1; |
@@ -32,24 +33,26 @@ discard block |
||
32 | 33 | { |
33 | 34 | // \VoidEngine\pre ($line_num .', '. ($skip_at > $line_num ? 'skip' : 'not skip') .': '. $line); |
34 | 35 | |
35 | - if ($skip_at > $line_num || !self::filter ($line)) |
|
36 | - continue; |
|
36 | + if ($skip_at > $line_num || !self::filter ($line)) { |
|
37 | + continue; |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $height = self::getHeight ($line); |
39 | 41 | $words = array_filter (explode (' ', $line), 'VLF\Parser::filter'); |
40 | 42 | $poped = false; |
41 | 43 | |
42 | 44 | # Очищаем стек объектов |
43 | - while ($objects->size () > 0) |
|
44 | - if ($objects->current ()->height >= $height) |
|
45 | + while ($objects->size () > 0) { |
|
46 | + if ($objects->current ()->height >= $height) |
|
45 | 47 | { |
46 | 48 | $objects->pop (); |
49 | + } |
|
47 | 50 | |
48 | 51 | $poped = true; |
52 | + } else { |
|
53 | + break; |
|
49 | 54 | } |
50 | 55 | |
51 | - else break; |
|
52 | - |
|
53 | 56 | # Создаём новую ссылку на объект |
54 | 57 | if ($poped && $objects->size () > 0) |
55 | 58 | { |
@@ -95,10 +98,11 @@ discard block |
||
95 | 98 | */ |
96 | 99 | if (isset ($words[0][1])) |
97 | 100 | { |
98 | - if ($words[0][1] == '^') |
|
99 | - $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
100 | - |
|
101 | - else throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
101 | + if ($words[0][1] == '^') { |
|
102 | + $skip_at = self::parseSubtext ($lines, $line_num, $height)[1]; |
|
103 | + } else { |
|
104 | + throw new \Exception ('Unknown char founded after comment definition at line '. ($line_num + 1)); |
|
105 | + } |
|
102 | 106 | } |
103 | 107 | |
104 | 108 | continue; |
@@ -122,9 +126,9 @@ discard block |
||
122 | 126 | |
123 | 127 | $code .= $parsed[0]; |
124 | 128 | $skip_at = $parsed[1]; |
129 | + } else { |
|
130 | + throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
125 | 131 | } |
126 | - |
|
127 | - else throw new \Exception ('Unknown char founded after runtime execution definition at line '. ($line_num + 1)); |
|
128 | 132 | } |
129 | 133 | |
130 | 134 | $tree->push (new Node ([ |
@@ -144,11 +148,13 @@ discard block |
||
144 | 148 | */ |
145 | 149 | elseif (($pos = strpos ($line, ':')) !== false) |
146 | 150 | { |
147 | - if ($objects->size () == 0) |
|
148 | - throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
151 | + if ($objects->size () == 0) { |
|
152 | + throw new \Exception ('Trying to set property to unknown object at line '. ($line_num + 1)); |
|
153 | + } |
|
149 | 154 | |
150 | - if (!isset ($words[1])) |
|
151 | - throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
155 | + if (!isset ($words[1])) { |
|
156 | + throw new \Exception ('Trying to set void property value at line '. ($line_num + 1)); |
|
157 | + } |
|
152 | 158 | |
153 | 159 | $propertyName = substr ($line, 0, $pos); |
154 | 160 | $propertyValue = substr ($line, $pos + 1); |
@@ -182,25 +188,27 @@ discard block |
||
182 | 188 | */ |
183 | 189 | elseif (isset ($words[0][1]) && $words[0][0] == '-' && $words[0][1] == '>') |
184 | 190 | { |
185 | - if ($objects->size () == 0) |
|
186 | - throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
191 | + if ($objects->size () == 0) { |
|
192 | + throw new \Exception ('Trying to call method from unknown object at line '. ($line_num + 1)); |
|
193 | + } |
|
187 | 194 | |
188 | 195 | $methodArgs = []; |
189 | 196 | |
190 | 197 | if (($pos = strpos ($line, '(')) !== false) |
191 | 198 | { |
192 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
193 | - throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
199 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
200 | + throw new \Exception ('Incorrect method arguments syntax at line '. ($line_num + 1)); |
|
201 | + } |
|
194 | 202 | |
195 | 203 | $methodArgs = substr ($line, $pos + 1, $end - $pos - 1); |
196 | 204 | |
197 | 205 | $methodName = trim (substr ($line, 2, $pos - 2)); |
198 | 206 | $methodArgs = self::filter ($methodArgs) ? |
199 | 207 | self::parseArguments ($methodArgs) : []; |
208 | + } else { |
|
209 | + $methodName = trim (substr ($line, 2)); |
|
200 | 210 | } |
201 | 211 | |
202 | - else $methodName = trim (substr ($line, 2)); |
|
203 | - |
|
204 | 212 | $objects->current ()->push (new Node ([ |
205 | 213 | 'type' => METHOD_CALL, |
206 | 214 | 'line' => $line, |
@@ -224,13 +232,15 @@ discard block |
||
224 | 232 | $args = []; |
225 | 233 | $styles = []; |
226 | 234 | |
227 | - if ($objects->size () > 0 && $objects->current ()->height < $height) |
|
228 | - $args[] = $objects->current ()->args['name']; |
|
235 | + if ($objects->size () > 0 && $objects->current ()->height < $height) { |
|
236 | + $args[] = $objects->current ()->args['name']; |
|
237 | + } |
|
229 | 238 | |
230 | 239 | if (($pos = strpos ($line, '(')) !== false) |
231 | 240 | { |
232 | - if (($end = strrpos ($line, ')', $pos)) === false) |
|
233 | - throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
241 | + if (($end = strrpos ($line, ')', $pos)) === false) { |
|
242 | + throw new \Exception ('Incorrect class constructor arguments syntax at line '. ($line_num + 1)); |
|
243 | + } |
|
234 | 244 | |
235 | 245 | $args = substr ($line, $pos + 1, $end - $pos - 1); |
236 | 246 | |
@@ -243,8 +253,9 @@ discard block |
||
243 | 253 | { |
244 | 254 | $styles = trim (substr ($line, $end + 3)); |
245 | 255 | |
246 | - if (strlen ($styles) == 0) |
|
247 | - throw new \Exception ('Trying to set empty style to object'); |
|
256 | + if (strlen ($styles) == 0) { |
|
257 | + throw new \Exception ('Trying to set empty style to object'); |
|
258 | + } |
|
248 | 259 | |
249 | 260 | $styles = array_map ('trim', explode (',', $styles)); |
250 | 261 | } |
@@ -269,7 +280,9 @@ discard block |
||
269 | 280 | /** |
270 | 281 | * Неопознанная структура |
271 | 282 | */ |
272 | - else throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
283 | + else { |
|
284 | + throw new \Exception ('Unsupported structure founded at line '. ($line_num + 1)); |
|
285 | + } |
|
273 | 286 | } |
274 | 287 | |
275 | 288 | return $tree; |
@@ -291,8 +304,9 @@ discard block |
||
291 | 304 | { |
292 | 305 | ++$height; |
293 | 306 | |
294 | - if ($line[$i] == "\t") |
|
295 | - $height += 3; |
|
307 | + if ($line[$i] == "\t") { |
|
308 | + $height += 3; |
|
309 | + } |
|
296 | 310 | |
297 | 311 | ++$i; |
298 | 312 | } |
@@ -329,8 +343,9 @@ discard block |
||
329 | 343 | |
330 | 344 | foreach ($lines as $line_id => $line) |
331 | 345 | { |
332 | - if ($line_id <= $begin_id) |
|
333 | - continue; |
|
346 | + if ($line_id <= $begin_id) { |
|
347 | + continue; |
|
348 | + } |
|
334 | 349 | |
335 | 350 | if (!self::filter ($line)) |
336 | 351 | { |
@@ -341,10 +356,11 @@ discard block |
||
341 | 356 | |
342 | 357 | $height = self::getHeight ($line); |
343 | 358 | |
344 | - if ($height > $down_height) |
|
345 | - $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
346 | - |
|
347 | - else return [$parsed, $line_id]; |
|
359 | + if ($height > $down_height) { |
|
360 | + $parsed .= str_repeat (' ', $height - $down_height) ."$line\n"; |
|
361 | + } else { |
|
362 | + return [$parsed, $line_id]; |
|
363 | + } |
|
348 | 364 | } |
349 | 365 | |
350 | 366 | return [$parsed, $line_id + 1]; |
@@ -370,18 +386,15 @@ discard block |
||
370 | 386 | { |
371 | 387 | $t .= $arguments[$i]; |
372 | 388 | |
373 | - if ($arguments[$i] == '\\') |
|
374 | - $canSplit = $i + 1; |
|
375 | - |
|
376 | - elseif ($canSplit < $i) |
|
389 | + if ($arguments[$i] == '\\') { |
|
390 | + $canSplit = $i + 1; |
|
391 | + } elseif ($canSplit < $i) |
|
377 | 392 | { |
378 | - if ($arguments[$i] == '\'' && !$split2) |
|
379 | - $split1 = !$split1; |
|
380 | - |
|
381 | - elseif ($arguments[$i] == '"' && !$split1) |
|
382 | - $split2 = !$split2; |
|
383 | - |
|
384 | - elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
|
393 | + if ($arguments[$i] == '\'' && !$split2) { |
|
394 | + $split1 = !$split1; |
|
395 | + } elseif ($arguments[$i] == '"' && !$split1) { |
|
396 | + $split2 = !$split2; |
|
397 | + } elseif (!$split1 && !$split2 && $arguments[$i] == ',') |
|
385 | 398 | { |
386 | 399 | $args[] = substr ($t, 0, -1); |
387 | 400 | $t = ''; |
@@ -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 $id => $node) |
|
27 | + foreach ($tree->getNodes() as $id => $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 |
@@ -33,15 +33,17 @@ discard block |
||
33 | 33 | $name = $node->args['name']; |
34 | 34 | $args = []; |
35 | 35 | |
36 | - if (isset (self::$objects[$name])) |
|
37 | - break; |
|
36 | + if (isset (self::$objects[$name])) { |
|
37 | + break; |
|
38 | + } |
|
38 | 39 | |
39 | 40 | if (isset ($node->args['args'])) |
40 | 41 | { |
41 | 42 | $args = $node->args['args']; |
42 | 43 | |
43 | - foreach ($args as $arg_id => $arg) |
|
44 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
44 | + foreach ($args as $arg_id => $arg) { |
|
45 | + $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
46 | + } |
|
45 | 47 | } |
46 | 48 | |
47 | 49 | try |
@@ -51,15 +53,12 @@ discard block |
||
51 | 53 | try |
52 | 54 | { |
53 | 55 | self::$objects[$name]->name = $name; |
54 | - } |
|
55 | - |
|
56 | - catch (\Throwable $e) {} |
|
57 | - } |
|
58 | - |
|
59 | - catch (\Throwable $e) |
|
56 | + } catch (\Throwable $e) {} |
|
57 | + } catch (\Throwable $e) |
|
60 | 58 | { |
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); |
|
59 | + if (self::$throw_errors) { |
|
60 | + throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
61 | + } |
|
63 | 62 | } |
64 | 63 | break; |
65 | 64 | |
@@ -78,13 +77,15 @@ discard block |
||
78 | 77 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
79 | 78 | $use = explode (' ', $use); |
80 | 79 | |
81 | - foreach ($use as $id => $useParam) |
|
82 | - if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
80 | + foreach ($use as $id => $useParam) { |
|
81 | + if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
83 | 82 | { |
84 | 83 | $fname = $use[$id + 1]; |
84 | + } |
|
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 | 90 | $preset .= "$fname = $useParam; "; |
90 | 91 | |
@@ -93,27 +94,26 @@ discard block |
||
93 | 94 | |
94 | 95 | $preset = self::formatLine ($preset, self::$objects); |
95 | 96 | $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
97 | + } else { |
|
98 | + $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
96 | 99 | } |
97 | 100 | |
98 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
99 | - |
|
100 | 101 | try |
101 | 102 | { |
102 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
103 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
104 | - |
|
105 | - else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
106 | - } |
|
107 | - |
|
108 | - catch (\Throwable $e) |
|
103 | + if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) { |
|
104 | + eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
105 | + } else { |
|
106 | + self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
107 | + } |
|
108 | + } catch (\Throwable $e) |
|
109 | 109 | { |
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); |
|
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); |
|
112 | + } |
|
112 | 113 | } |
114 | + } elseif (self::$throw_errors) { |
|
115 | + throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
113 | 116 | } |
114 | - |
|
115 | - elseif (self::$throw_errors) |
|
116 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
117 | 117 | break; |
118 | 118 | |
119 | 119 | case METHOD_CALL: |
@@ -124,29 +124,28 @@ discard block |
||
124 | 124 | $methodName = $node->args['name']; |
125 | 125 | $methodArgs = $node->args['args']; |
126 | 126 | |
127 | - foreach ($methodArgs as $arg_id => $arg) |
|
128 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
127 | + foreach ($methodArgs as $arg_id => $arg) { |
|
128 | + $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
129 | + } |
|
129 | 130 | |
130 | 131 | try |
131 | 132 | { |
132 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
133 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
134 | - |
|
135 | - elseif (sizeof ($methodArgs) > 0) |
|
136 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
137 | - |
|
138 | - else self::$objects[$name]->$methodName (); |
|
139 | - } |
|
140 | - |
|
141 | - catch (\Throwable $e) |
|
133 | + if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) { |
|
134 | + eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
135 | + } elseif (sizeof ($methodArgs) > 0) { |
|
136 | + self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
137 | + } else { |
|
138 | + self::$objects[$name]->$methodName (); |
|
139 | + } |
|
140 | + } catch (\Throwable $e) |
|
142 | 141 | { |
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); |
|
142 | + if (self::$throw_errors) { |
|
143 | + 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 | + } |
|
145 | 145 | } |
146 | + } elseif (self::$throw_errors) { |
|
147 | + throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
146 | 148 | } |
147 | - |
|
148 | - elseif (self::$throw_errors) |
|
149 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
150 | 149 | break; |
151 | 150 | |
152 | 151 | case STYLES_IMPORTING: |
@@ -156,11 +155,10 @@ discard block |
||
156 | 155 | |
157 | 156 | if (!file_exists ($path)) |
158 | 157 | { |
159 | - if (self::$throw_errors) |
|
160 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
161 | - } |
|
162 | - |
|
163 | - elseif (!isset (self::$imported_styles[$path])) |
|
158 | + if (self::$throw_errors) { |
|
159 | + throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
160 | + } |
|
161 | + } elseif (!isset (self::$imported_styles[$path])) |
|
164 | 162 | { |
165 | 163 | \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
166 | 164 | |
@@ -178,16 +176,17 @@ discard block |
||
178 | 176 | |
179 | 177 | if ($node->type == OBJECT_DEFINITION) |
180 | 178 | { |
181 | - if (isset (\VLF\VST\Interpreter::$default_styles[$node->args['class']])) |
|
182 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
179 | + if (isset (\VLF\VST\Interpreter::$default_styles[$node->args['class']])) { |
|
180 | + $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$default_styles[$node->args['class']]); |
|
181 | + } |
|
183 | 182 | |
184 | - if (isset ($node->args['styles'])) |
|
185 | - foreach ($node->args['styles'] as $style) |
|
183 | + if (isset ($node->args['styles'])) { |
|
184 | + foreach ($node->args['styles'] as $style) |
|
186 | 185 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
187 | 186 | $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
188 | - |
|
189 | - elseif (self::$throw_errors) |
|
190 | - throw new \Exception ('Trying to set undefined style "'. $style .'" to object at line "'. $node->line .'"'); |
|
187 | + } elseif (self::$throw_errors) { |
|
188 | + throw new \Exception ('Trying to set undefined style "'. $style .'" to object at line "'. $node->line .'"'); |
|
189 | + } |
|
191 | 190 | } |
192 | 191 | |
193 | 192 | self::$objects = self::run (new AST (array_map ( |
@@ -228,8 +227,9 @@ discard block |
||
228 | 227 | |
229 | 228 | $nReplacement = []; |
230 | 229 | |
231 | - foreach ($replacement as $replaceTo => $nLn) |
|
232 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
230 | + foreach ($replacement as $replaceTo => $nLn) { |
|
231 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | $replacement = $nReplacement; |
235 | 235 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -238,10 +238,11 @@ discard block |
||
238 | 238 | { |
239 | 239 | $replaced = false; |
240 | 240 | |
241 | - foreach ($replacement as $name => $replaceAt) |
|
242 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
241 | + foreach ($replacement as $name => $replaceAt) { |
|
242 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
243 | 243 | { |
244 | 244 | $newLine .= $replaceAt; |
245 | + } |
|
245 | 246 | |
246 | 247 | $i += $l - 1; |
247 | 248 | $replaced = true; |
@@ -249,8 +250,9 @@ discard block |
||
249 | 250 | break; |
250 | 251 | } |
251 | 252 | |
252 | - if (!$replaced) |
|
253 | - $newLine .= $line[$i]; |
|
253 | + if (!$replaced) { |
|
254 | + $newLine .= $line[$i]; |
|
255 | + } |
|
254 | 256 | } |
255 | 257 | |
256 | 258 | $line = $newLine; |
@@ -10,44 +10,44 @@ discard block |
||
10 | 10 | // protected ?string $name = null; |
11 | 11 | // protected bool $isCollection = false; |
12 | 12 | |
13 | - public function __construct ($name, $assembly = false, ...$args) |
|
13 | + public function __construct($name, $assembly = false, ...$args) |
|
14 | 14 | { |
15 | 15 | foreach ($args as $id => $arg) |
16 | - $args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
16 | + $args[$id] = EngineAdditions::uncoupleSelector($arg); |
|
17 | 17 | |
18 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
18 | + if (is_int($name) && VoidCore::objectExists($name)) |
|
19 | 19 | $this->selector = $name; |
20 | 20 | |
21 | - elseif (is_string ($name)) |
|
22 | - $this->selector = VoidCore::createObject ($name, $assembly, ...$args); |
|
21 | + elseif (is_string($name)) |
|
22 | + $this->selector = VoidCore::createObject($name, $assembly, ...$args); |
|
23 | 23 | |
24 | - else throw new \Exception ('Incorrect params passed'); |
|
24 | + else throw new \Exception('Incorrect params passed'); |
|
25 | 25 | |
26 | 26 | /*$this->isCollection = $this->getType () |
27 | 27 | ->isSubclassOf (VoidCore::typeof ('System.Collectons.Generic.ICollection'));*/ |
28 | 28 | } |
29 | 29 | |
30 | - public function dispose (): void |
|
30 | + public function dispose(): void |
|
31 | 31 | { |
32 | - VoidCore::removeObjects ($this->selector); |
|
32 | + VoidCore::removeObjects($this->selector); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | # Основные магические методы |
36 | 36 | |
37 | - public function __get (string $name) |
|
37 | + public function __get(string $name) |
|
38 | 38 | { |
39 | - switch (strtolower ($name)) |
|
39 | + switch (strtolower($name)) |
|
40 | 40 | { |
41 | 41 | case 'count': |
42 | 42 | case 'length': |
43 | 43 | try |
44 | 44 | { |
45 | - return $this->getProperty ('Count'); |
|
45 | + return $this->getProperty('Count'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | catch (\WinformsException $e) |
49 | 49 | { |
50 | - return $this->getProperty ('Length'); |
|
50 | + return $this->getProperty('Length'); |
|
51 | 51 | } |
52 | 52 | break; |
53 | 53 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | $list = []; |
57 | 57 | |
58 | 58 | for ($i = 0; $i < $size; ++$i) |
59 | - $list[] = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $i)); |
|
59 | + $list[] = EngineAdditions::coupleSelector(VoidCore::getArrayValue($this->selector, $i)); |
|
60 | 60 | |
61 | 61 | return $list; |
62 | 62 | break; |
@@ -68,93 +68,91 @@ discard block |
||
68 | 68 | for ($i = 0; $i < $size; ++$i) |
69 | 69 | try |
70 | 70 | { |
71 | - $names[] = VoidCore::getProperty (VoidCore::getArrayValue ($this->selector, [$i, VC_OBJECT]), 'Text'); |
|
71 | + $names[] = VoidCore::getProperty(VoidCore::getArrayValue($this->selector, [$i, VC_OBJECT]), 'Text'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | catch (\WinformsException $e) |
75 | 75 | { |
76 | - $names[] = VoidCore::getArrayValue ($this->selector, [$i, VC_STRING]); |
|
76 | + $names[] = VoidCore::getArrayValue($this->selector, [$i, VC_STRING]); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | return $names; |
80 | 80 | break; |
81 | 81 | } |
82 | 82 | |
83 | - if (method_exists ($this, $method = 'get_'. $name)) |
|
84 | - return $this->$method (); |
|
83 | + if (method_exists($this, $method = 'get_'.$name)) |
|
84 | + return $this->$method(); |
|
85 | 85 | |
86 | 86 | return isset ($this->$name) ? |
87 | - $this->$name : EngineAdditions::coupleSelector ($this->getProperty ($name)); |
|
87 | + $this->$name : EngineAdditions::coupleSelector($this->getProperty($name)); |
|
88 | 88 | } |
89 | 89 | |
90 | - public function __set (string $name, $value): void |
|
90 | + public function __set(string $name, $value): void |
|
91 | 91 | { |
92 | - if (substr ($name, -5) == 'Event') |
|
93 | - Events::setEvent ($this->selector, substr ($name, 0, -5), $value); |
|
92 | + if (substr($name, -5) == 'Event') |
|
93 | + Events::setEvent($this->selector, substr($name, 0, -5), $value); |
|
94 | 94 | |
95 | - elseif (method_exists ($this, $method = 'set_'. $name)) |
|
96 | - $this->$method ($value); |
|
95 | + elseif (method_exists($this, $method = 'set_'.$name)) |
|
96 | + $this->$method($value); |
|
97 | 97 | |
98 | - else $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
98 | + else $this->setProperty($name, EngineAdditions::uncoupleSelector($value)); |
|
99 | 99 | } |
100 | 100 | |
101 | - public function __call (string $name, array $args) |
|
101 | + public function __call(string $name, array $args) |
|
102 | 102 | { |
103 | - return EngineAdditions::coupleSelector ($this->callMethod ($name, |
|
104 | - array_map ('VoidEngine\\EngineAdditions::uncoupleSelector', $args))); |
|
103 | + return EngineAdditions::coupleSelector($this->callMethod($name, |
|
104 | + array_map('VoidEngine\\EngineAdditions::uncoupleSelector', $args))); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | # Управление VoidCore |
108 | 108 | |
109 | - protected function getProperty ($name) |
|
109 | + protected function getProperty($name) |
|
110 | 110 | { |
111 | - return VoidCore::getProperty ($this->selector, $name); |
|
111 | + return VoidCore::getProperty($this->selector, $name); |
|
112 | 112 | } |
113 | 113 | |
114 | - protected function setProperty (string $name, $value): void |
|
114 | + protected function setProperty(string $name, $value): void |
|
115 | 115 | { |
116 | - VoidCore::setProperty ($this->selector, $name, $value); |
|
116 | + VoidCore::setProperty($this->selector, $name, $value); |
|
117 | 117 | } |
118 | 118 | |
119 | - protected function callMethod (string $name, array $args = []) |
|
119 | + protected function callMethod(string $name, array $args = []) |
|
120 | 120 | { |
121 | - return VoidCore::callMethod ($this->selector, $name, ...$args); |
|
121 | + return VoidCore::callMethod($this->selector, $name, ...$args); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | # ArrayAccess |
125 | 125 | |
126 | - public function offsetSet ($index, $value) |
|
126 | + public function offsetSet($index, $value) |
|
127 | 127 | { |
128 | 128 | try |
129 | 129 | { |
130 | 130 | $index === null ? |
131 | - $this->callMethod ('Add', EngineAdditions::uncoupleSelector ($value)) : |
|
132 | - $this->callMethod ('Insert', $index, EngineAdditions::uncoupleSelector ($value)); |
|
131 | + $this->callMethod('Add', EngineAdditions::uncoupleSelector($value)) : $this->callMethod('Insert', $index, EngineAdditions::uncoupleSelector($value)); |
|
133 | 132 | } |
134 | 133 | |
135 | 134 | catch (\Throwable $e) |
136 | 135 | { |
137 | 136 | $index === null ? |
138 | - VoidCore::setArrayValue ($this->selector, $this->count, EngineAdditions::uncoupleSelector ($value)) : |
|
139 | - VoidCore::setArrayValue ($this->selector, $index, EngineAdditions::uncoupleSelector ($value)); |
|
137 | + VoidCore::setArrayValue($this->selector, $this->count, EngineAdditions::uncoupleSelector($value)) : VoidCore::setArrayValue($this->selector, $index, EngineAdditions::uncoupleSelector($value)); |
|
140 | 138 | } |
141 | 139 | } |
142 | 140 | |
143 | - public function offsetGet ($index) |
|
141 | + public function offsetGet($index) |
|
144 | 142 | { |
145 | - return EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $index), $this->selector); |
|
143 | + return EngineAdditions::coupleSelector(VoidCore::getArrayValue($this->selector, $index), $this->selector); |
|
146 | 144 | } |
147 | 145 | |
148 | - public function offsetUnset ($index): void |
|
146 | + public function offsetUnset($index): void |
|
149 | 147 | { |
150 | - $this->callMethod ('RemoveAt', $index); |
|
148 | + $this->callMethod('RemoveAt', $index); |
|
151 | 149 | } |
152 | 150 | |
153 | - public function offsetExists ($index): bool |
|
151 | + public function offsetExists($index): bool |
|
154 | 152 | { |
155 | 153 | try |
156 | 154 | { |
157 | - $this->offsetGet ($index); |
|
155 | + $this->offsetGet($index); |
|
158 | 156 | } |
159 | 157 | |
160 | 158 | catch (\WinformsException $e) |
@@ -172,16 +170,16 @@ discard block |
||
172 | 170 | $size = $this->count; |
173 | 171 | |
174 | 172 | for ($i = 0; $i < $size; ++$i) |
175 | - $callback (EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
173 | + $callback(EngineAdditions::coupleSelector(VoidCore::getArrayValue($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
176 | 174 | } |
177 | 175 | |
178 | - public function where (callable $comparator, string $type = null): array |
|
176 | + public function where(callable $comparator, string $type = null): array |
|
179 | 177 | { |
180 | 178 | $size = $this->count; |
181 | 179 | $return = []; |
182 | 180 | |
183 | 181 | for ($i = 0; $i < $size; ++$i) |
184 | - if ($comparator ($value = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
182 | + if ($comparator($value = EngineAdditions::coupleSelector(VoidCore::getArrayValue($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
185 | 183 | $return[] = $value; |
186 | 184 | |
187 | 185 | return $return; |
@@ -189,30 +187,30 @@ discard block |
||
189 | 187 | |
190 | 188 | # Магические методы |
191 | 189 | |
192 | - public function __destruct () |
|
190 | + public function __destruct() |
|
193 | 191 | { |
194 | - VoidCore::destructObject ($this->selector); |
|
192 | + VoidCore::destructObject($this->selector); |
|
195 | 193 | } |
196 | 194 | |
197 | - public function __toString (): string |
|
195 | + public function __toString(): string |
|
198 | 196 | { |
199 | 197 | return $this->selector; |
200 | 198 | } |
201 | 199 | |
202 | - public function __debugInfo (): array |
|
200 | + public function __debugInfo(): array |
|
203 | 201 | { |
204 | 202 | $info = ['selector' => $this->selector]; |
205 | 203 | |
206 | 204 | try |
207 | 205 | { |
208 | - $info['name'] = $this->getProperty ('Name'); |
|
206 | + $info['name'] = $this->getProperty('Name'); |
|
209 | 207 | } |
210 | 208 | |
211 | 209 | catch (\WinformsException $e) {} |
212 | 210 | |
213 | 211 | try |
214 | 212 | { |
215 | - $info['info'] = $this->callMethod ('ToString'); |
|
213 | + $info['info'] = $this->callMethod('ToString'); |
|
216 | 214 | } |
217 | 215 | |
218 | 216 | catch (\WinformsException $e) {} |
@@ -223,29 +221,29 @@ discard block |
||
223 | 221 | |
224 | 222 | class NetClass extends NetObject |
225 | 223 | { |
226 | - public function __construct ($name, $assembly = false) |
|
224 | + public function __construct($name, $assembly = false) |
|
227 | 225 | { |
228 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
226 | + if (is_int($name) && VoidCore::objectExists($name)) |
|
229 | 227 | $this->selector = $name; |
230 | 228 | |
231 | - elseif (is_string ($name)) |
|
232 | - $this->selector = VoidCore::getClass ($name, $assembly); |
|
229 | + elseif (is_string($name)) |
|
230 | + $this->selector = VoidCore::getClass($name, $assembly); |
|
233 | 231 | |
234 | - else throw new \Exception ('Incorrect params passed'); |
|
232 | + else throw new \Exception('Incorrect params passed'); |
|
235 | 233 | } |
236 | 234 | } |
237 | 235 | |
238 | 236 | class EngineAdditions |
239 | 237 | { |
240 | - public static function coupleSelector ($selector) |
|
238 | + public static function coupleSelector($selector) |
|
241 | 239 | { |
242 | - return is_int ($selector) && VoidCore::objectExists ($selector) ? |
|
243 | - new NetObject ($selector) : $selector; |
|
240 | + return is_int($selector) && VoidCore::objectExists($selector) ? |
|
241 | + new NetObject($selector) : $selector; |
|
244 | 242 | } |
245 | 243 | |
246 | - public static function uncoupleSelector ($object) |
|
244 | + public static function uncoupleSelector($object) |
|
247 | 245 | { |
248 | - return is_object ($object) && $object instanceof NetObject ? |
|
246 | + return is_object($object) && $object instanceof NetObject ? |
|
249 | 247 | $object->selector : $object; |
250 | 248 | } |
251 | 249 | } |
@@ -12,16 +12,17 @@ discard block |
||
12 | 12 | |
13 | 13 | public function __construct ($name, $assembly = false, ...$args) |
14 | 14 | { |
15 | - foreach ($args as $id => $arg) |
|
16 | - $args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
15 | + foreach ($args as $id => $arg) { |
|
16 | + $args[$id] = EngineAdditions::uncoupleSelector ($arg); |
|
17 | + } |
|
17 | 18 | |
18 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
19 | - $this->selector = $name; |
|
20 | - |
|
21 | - elseif (is_string ($name)) |
|
22 | - $this->selector = VoidCore::createObject ($name, $assembly, ...$args); |
|
23 | - |
|
24 | - else throw new \Exception ('Incorrect params passed'); |
|
19 | + if (is_int ($name) && VoidCore::objectExists ($name)) { |
|
20 | + $this->selector = $name; |
|
21 | + } elseif (is_string ($name)) { |
|
22 | + $this->selector = VoidCore::createObject ($name, $assembly, ...$args); |
|
23 | + } else { |
|
24 | + throw new \Exception ('Incorrect params passed'); |
|
25 | + } |
|
25 | 26 | |
26 | 27 | /*$this->isCollection = $this->getType () |
27 | 28 | ->isSubclassOf (VoidCore::typeof ('System.Collectons.Generic.ICollection'));*/ |
@@ -43,9 +44,7 @@ discard block |
||
43 | 44 | try |
44 | 45 | { |
45 | 46 | return $this->getProperty ('Count'); |
46 | - } |
|
47 | - |
|
48 | - catch (\WinformsException $e) |
|
47 | + } catch (\WinformsException $e) |
|
49 | 48 | { |
50 | 49 | return $this->getProperty ('Length'); |
51 | 50 | } |
@@ -55,8 +54,9 @@ discard block |
||
55 | 54 | $size = $this->count; |
56 | 55 | $list = []; |
57 | 56 | |
58 | - for ($i = 0; $i < $size; ++$i) |
|
59 | - $list[] = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $i)); |
|
57 | + for ($i = 0; $i < $size; ++$i) { |
|
58 | + $list[] = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $i)); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | return $list; |
62 | 62 | break; |
@@ -65,13 +65,12 @@ discard block |
||
65 | 65 | $size = $this->count; |
66 | 66 | $names = []; |
67 | 67 | |
68 | - for ($i = 0; $i < $size; ++$i) |
|
69 | - try |
|
68 | + for ($i = 0; $i < $size; ++$i) { |
|
69 | + try |
|
70 | 70 | { |
71 | 71 | $names[] = VoidCore::getProperty (VoidCore::getArrayValue ($this->selector, [$i, VC_OBJECT]), 'Text'); |
72 | - } |
|
73 | - |
|
74 | - catch (\WinformsException $e) |
|
72 | + } |
|
73 | + } catch (\WinformsException $e) |
|
75 | 74 | { |
76 | 75 | $names[] = VoidCore::getArrayValue ($this->selector, [$i, VC_STRING]); |
77 | 76 | } |
@@ -80,8 +79,9 @@ discard block |
||
80 | 79 | break; |
81 | 80 | } |
82 | 81 | |
83 | - if (method_exists ($this, $method = 'get_'. $name)) |
|
84 | - return $this->$method (); |
|
82 | + if (method_exists ($this, $method = 'get_'. $name)) { |
|
83 | + return $this->$method (); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | return isset ($this->$name) ? |
87 | 87 | $this->$name : EngineAdditions::coupleSelector ($this->getProperty ($name)); |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | |
90 | 90 | public function __set (string $name, $value): void |
91 | 91 | { |
92 | - if (substr ($name, -5) == 'Event') |
|
93 | - Events::setEvent ($this->selector, substr ($name, 0, -5), $value); |
|
94 | - |
|
95 | - elseif (method_exists ($this, $method = 'set_'. $name)) |
|
96 | - $this->$method ($value); |
|
97 | - |
|
98 | - else $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
92 | + if (substr ($name, -5) == 'Event') { |
|
93 | + Events::setEvent ($this->selector, substr ($name, 0, -5), $value); |
|
94 | + } elseif (method_exists ($this, $method = 'set_'. $name)) { |
|
95 | + $this->$method ($value); |
|
96 | + } else { |
|
97 | + $this->setProperty ($name, EngineAdditions::uncoupleSelector ($value)); |
|
98 | + } |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function __call (string $name, array $args) |
@@ -130,9 +130,7 @@ discard block |
||
130 | 130 | $index === null ? |
131 | 131 | $this->callMethod ('Add', EngineAdditions::uncoupleSelector ($value)) : |
132 | 132 | $this->callMethod ('Insert', $index, EngineAdditions::uncoupleSelector ($value)); |
133 | - } |
|
134 | - |
|
135 | - catch (\Throwable $e) |
|
133 | + } catch (\Throwable $e) |
|
136 | 134 | { |
137 | 135 | $index === null ? |
138 | 136 | VoidCore::setArrayValue ($this->selector, $this->count, EngineAdditions::uncoupleSelector ($value)) : |
@@ -155,9 +153,7 @@ discard block |
||
155 | 153 | try |
156 | 154 | { |
157 | 155 | $this->offsetGet ($index); |
158 | - } |
|
159 | - |
|
160 | - catch (\WinformsException $e) |
|
156 | + } catch (\WinformsException $e) |
|
161 | 157 | { |
162 | 158 | return false; |
163 | 159 | } |
@@ -171,8 +167,9 @@ discard block |
||
171 | 167 | { |
172 | 168 | $size = $this->count; |
173 | 169 | |
174 | - for ($i = 0; $i < $size; ++$i) |
|
175 | - $callback (EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
170 | + for ($i = 0; $i < $size; ++$i) { |
|
171 | + $callback (EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i); |
|
172 | + } |
|
176 | 173 | } |
177 | 174 | |
178 | 175 | public function where (callable $comparator, string $type = null): array |
@@ -180,9 +177,10 @@ discard block |
||
180 | 177 | $size = $this->count; |
181 | 178 | $return = []; |
182 | 179 | |
183 | - for ($i = 0; $i < $size; ++$i) |
|
184 | - if ($comparator ($value = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
180 | + for ($i = 0; $i < $size; ++$i) { |
|
181 | + if ($comparator ($value = EngineAdditions::coupleSelector (VoidCore::getArrayValue ($this->selector, $type !== null ? [$i, $type] : $i), $this->selector), $i)) |
|
185 | 182 | $return[] = $value; |
183 | + } |
|
186 | 184 | |
187 | 185 | return $return; |
188 | 186 | } |
@@ -206,16 +204,12 @@ discard block |
||
206 | 204 | try |
207 | 205 | { |
208 | 206 | $info['name'] = $this->getProperty ('Name'); |
209 | - } |
|
210 | - |
|
211 | - catch (\WinformsException $e) {} |
|
207 | + } catch (\WinformsException $e) {} |
|
212 | 208 | |
213 | 209 | try |
214 | 210 | { |
215 | 211 | $info['info'] = $this->callMethod ('ToString'); |
216 | - } |
|
217 | - |
|
218 | - catch (\WinformsException $e) {} |
|
212 | + } catch (\WinformsException $e) {} |
|
219 | 213 | |
220 | 214 | return $info; |
221 | 215 | } |
@@ -225,13 +219,13 @@ discard block |
||
225 | 219 | { |
226 | 220 | public function __construct ($name, $assembly = false) |
227 | 221 | { |
228 | - if (is_int ($name) && VoidCore::objectExists ($name)) |
|
229 | - $this->selector = $name; |
|
230 | - |
|
231 | - elseif (is_string ($name)) |
|
232 | - $this->selector = VoidCore::getClass ($name, $assembly); |
|
233 | - |
|
234 | - else throw new \Exception ('Incorrect params passed'); |
|
222 | + if (is_int ($name) && VoidCore::objectExists ($name)) { |
|
223 | + $this->selector = $name; |
|
224 | + } elseif (is_string ($name)) { |
|
225 | + $this->selector = VoidCore::getClass ($name, $assembly); |
|
226 | + } else { |
|
227 | + throw new \Exception ('Incorrect params passed'); |
|
228 | + } |
|
235 | 229 | } |
236 | 230 | } |
237 | 231 |