@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | { |
12 | 12 | public $class = 'System.Windows.Forms.ListViewItem'; |
13 | 13 | |
14 | - public function __construct (string $text = '') |
|
14 | + public function __construct(string $text = '') |
|
15 | 15 | { |
16 | - parent::__construct (null, $this->class); |
|
16 | + parent::__construct(null, $this->class); |
|
17 | 17 | |
18 | 18 | $this->text = $text; |
19 | 19 | } |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | { |
24 | 24 | public $class = 'System.Windows.Forms.ColumnHeader'; |
25 | 25 | |
26 | - public function __construct (string $text = '') |
|
26 | + public function __construct(string $text = '') |
|
27 | 27 | { |
28 | - parent::__construct (null, $this->class); |
|
28 | + parent::__construct(null, $this->class); |
|
29 | 29 | |
30 | 30 | $this->text = $text; |
31 | 31 | } |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | { |
36 | 36 | public $class = 'System.Windows.Forms.ListViewGroup'; |
37 | 37 | |
38 | - public function __construct (string $text = '') |
|
38 | + public function __construct(string $text = '') |
|
39 | 39 | { |
40 | - parent::__construct (null, $this->class); |
|
40 | + parent::__construct(null, $this->class); |
|
41 | 41 | |
42 | 42 | $this->header = $text; |
43 | 43 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | return [ |
49 | 49 | 'text' => $e->getMessage (), |
50 | - 'line' => $e->getLine () |
|
50 | + 'line' => $e->getLine () |
|
51 | 51 | ]; |
52 | 52 | } |
53 | 53 | |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | |
166 | 166 | function substr_icount (string $haystack, string $needle, ...$params): int |
167 | 167 | { |
168 | - return substr_count (strtolower ($haystack), strtolower ($needle), ...$params); |
|
168 | + return substr_count (strtolower ($haystack), strtolower ($needle), ...$params); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | function str_replace_assoc (string $subject, array $replacements): string |
172 | 172 | { |
173 | - return str_replace (array_keys ($replacements), array_values ($replacements), $subject); |
|
173 | + return str_replace (array_keys ($replacements), array_values ($replacements), $subject); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function pre (...$args): void |
177 | 177 | { |
178 | - message (sizeof ($args) < 2 ? current ($args) : $args); |
|
178 | + message (sizeof ($args) < 2 ? current ($args) : $args); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | function messageBox (string $message, string $caption = '', ...$args) |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | catch (\Throwable $e) |
336 | - { |
|
337 | - continue; |
|
338 | - } |
|
336 | + { |
|
337 | + continue; |
|
338 | + } |
|
339 | 339 | |
340 | 340 | return false; |
341 | 341 | } |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | call_user_func ($function, $self); |
359 | 359 | }; |
360 | 360 | |
361 | - $timer->start (); |
|
361 | + $timer->start (); |
|
362 | 362 | |
363 | 363 | return $timer; |
364 | 364 | } |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | |
379 | 379 | $timer->start (); |
380 | 380 | |
381 | - return $timer; |
|
381 | + return $timer; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | class Clipboard |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace VoidEngine; |
4 | 4 | |
5 | -function err_status (bool $status = null): bool |
|
5 | +function err_status(bool $status = null): bool |
|
6 | 6 | { |
7 | 7 | $oldStatus = $GLOBALS['__debug']['error_status']; |
8 | 8 | |
@@ -12,216 +12,216 @@ discard block |
||
12 | 12 | return $oldStatus; |
13 | 13 | } |
14 | 14 | |
15 | -function err_no (): bool |
|
15 | +function err_no(): bool |
|
16 | 16 | { |
17 | - return err_status (false); |
|
17 | + return err_status(false); |
|
18 | 18 | } |
19 | 19 | |
20 | -function err_yes (): bool |
|
20 | +function err_yes(): bool |
|
21 | 21 | { |
22 | - return err_status (true); |
|
22 | + return err_status(true); |
|
23 | 23 | } |
24 | 24 | |
25 | -function run (string $path, ...$args) |
|
25 | +function run(string $path, ...$args) |
|
26 | 26 | { |
27 | - return (new Process)->start ($path, ...$args); |
|
27 | + return (new Process)->start($path, ...$args); |
|
28 | 28 | } |
29 | 29 | |
30 | -function vbs_exec (string $code) |
|
30 | +function vbs_exec(string $code) |
|
31 | 31 | { |
32 | - file_put_contents ($path = getenv ('temp') .'/'. crc32 ($code) .'.vbs', $code); |
|
32 | + file_put_contents($path = getenv('temp').'/'.crc32($code).'.vbs', $code); |
|
33 | 33 | |
34 | - (new \COM ('WScript.Shell'))->Run ($path, 0, true); |
|
34 | + (new \COM('WScript.Shell'))->Run($path, 0, true); |
|
35 | 35 | |
36 | - unlink ($path); |
|
36 | + unlink($path); |
|
37 | 37 | } |
38 | 38 | |
39 | -function php_errors_check (string $code): ?array |
|
39 | +function php_errors_check(string $code): ?array |
|
40 | 40 | { |
41 | 41 | try |
42 | 42 | { |
43 | - eval ('return; '. $code); |
|
43 | + eval ('return; '.$code); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | catch (\Throwable $e) |
47 | 47 | { |
48 | 48 | return [ |
49 | - 'text' => $e->getMessage (), |
|
50 | - 'line' => $e->getLine () |
|
49 | + 'text' => $e->getMessage(), |
|
50 | + 'line' => $e->getLine() |
|
51 | 51 | ]; |
52 | 52 | } |
53 | 53 | |
54 | 54 | return null; |
55 | 55 | } |
56 | 56 | |
57 | -function enum (string $name): array |
|
57 | +function enum(string $name): array |
|
58 | 58 | { |
59 | 59 | return [ |
60 | - substr ($name, strrpos ($name, '.') + 1), |
|
61 | - ($name = substr ($name, 0, strrpos ($name, '.'))) .', '. substr ($name, 0, strrpos ($name, '.')) |
|
60 | + substr($name, strrpos($name, '.') + 1), |
|
61 | + ($name = substr($name, 0, strrpos($name, '.'))).', '.substr($name, 0, strrpos($name, '.')) |
|
62 | 62 | ]; |
63 | 63 | } |
64 | 64 | |
65 | -function enum_parse (string $baseType, string $value) |
|
65 | +function enum_parse(string $baseType, string $value) |
|
66 | 66 | { |
67 | 67 | try |
68 | 68 | { |
69 | - return VoidEngine::callMethod (VoidEngine::createClass ('System.Enum',''), ['parse', 'object'], VoidEngine::objectType ($baseType), $value, true); |
|
69 | + return VoidEngine::callMethod(VoidEngine::createClass('System.Enum', ''), ['parse', 'object'], VoidEngine::objectType($baseType), $value, true); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | catch (\WinFormsException $e) |
73 | 73 | { |
74 | - return (new WFClass ($baseType))->$value; |
|
74 | + return (new WFClass($baseType))->$value; |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
78 | -function getNetArray (string $type, array $items = []): WFObject |
|
78 | +function getNetArray(string $type, array $items = []): WFObject |
|
79 | 79 | { |
80 | - $array = (new WFClass ('System.Array', null)) |
|
81 | - ->createInstance (VoidEngine::objectType ($type), $size = sizeof ($items)); |
|
80 | + $array = (new WFClass('System.Array', null)) |
|
81 | + ->createInstance(VoidEngine::objectType($type), $size = sizeof($items)); |
|
82 | 82 | |
83 | 83 | for ($i = 0; $i < $size; ++$i) |
84 | - $array[$i] = array_shift ($items); |
|
84 | + $array[$i] = array_shift($items); |
|
85 | 85 | |
86 | 86 | return $array; |
87 | 87 | } |
88 | 88 | |
89 | -function dir_create (string $path, int $mode = 0777): void |
|
89 | +function dir_create(string $path, int $mode = 0777): void |
|
90 | 90 | { |
91 | - if (!is_dir ($path)) |
|
92 | - mkdir ($path, $mode, true); |
|
91 | + if (!is_dir($path)) |
|
92 | + mkdir($path, $mode, true); |
|
93 | 93 | } |
94 | 94 | |
95 | -function dir_delete (string $path): bool |
|
95 | +function dir_delete(string $path): bool |
|
96 | 96 | { |
97 | - if (!is_dir ($path)) |
|
97 | + if (!is_dir($path)) |
|
98 | 98 | return false; |
99 | 99 | |
100 | - foreach (array_slice (scandir ($path), 2) as $file) |
|
101 | - if (is_dir ($file = $path .'/'. $file)) |
|
100 | + foreach (array_slice(scandir($path), 2) as $file) |
|
101 | + if (is_dir($file = $path.'/'.$file)) |
|
102 | 102 | { |
103 | - dir_delete ($file); |
|
103 | + dir_delete($file); |
|
104 | 104 | |
105 | - if (is_dir ($file)) |
|
106 | - rmdir ($file); |
|
105 | + if (is_dir($file)) |
|
106 | + rmdir($file); |
|
107 | 107 | } |
108 | 108 | |
109 | - else unlink ($file); |
|
109 | + else unlink($file); |
|
110 | 110 | |
111 | - rmdir ($path); |
|
111 | + rmdir($path); |
|
112 | 112 | |
113 | 113 | return true; |
114 | 114 | } |
115 | 115 | |
116 | -function dir_clean (string $path): void |
|
116 | +function dir_clean(string $path): void |
|
117 | 117 | { |
118 | - dir_delete ($path); |
|
119 | - dir_create ($path); |
|
118 | + dir_delete($path); |
|
119 | + dir_create($path); |
|
120 | 120 | } |
121 | 121 | |
122 | -function dir_copy (string $from, string $to): bool |
|
122 | +function dir_copy(string $from, string $to): bool |
|
123 | 123 | { |
124 | - if (!is_dir ($from)) |
|
124 | + if (!is_dir($from)) |
|
125 | 125 | return false; |
126 | 126 | |
127 | - if (!is_dir ($to)) |
|
128 | - dir_create ($to); |
|
127 | + if (!is_dir($to)) |
|
128 | + dir_create($to); |
|
129 | 129 | |
130 | - foreach (array_slice (scandir ($from), 2) as $file) |
|
131 | - if (is_dir ($f = $from .'/'. $file)) |
|
132 | - dir_copy ($f, $to .'/'. $file); |
|
130 | + foreach (array_slice(scandir($from), 2) as $file) |
|
131 | + if (is_dir($f = $from.'/'.$file)) |
|
132 | + dir_copy($f, $to.'/'.$file); |
|
133 | 133 | |
134 | - else copy ($f, $to .'/'. $file); |
|
134 | + else copy($f, $to.'/'.$file); |
|
135 | 135 | |
136 | 136 | return true; |
137 | 137 | } |
138 | 138 | |
139 | -function getARGBColor (string $color) |
|
139 | +function getARGBColor(string $color) |
|
140 | 140 | { |
141 | - return (new WFClass ('System.Drawing.ColorTranslator'))->fromHtml ($color); |
|
141 | + return (new WFClass('System.Drawing.ColorTranslator'))->fromHtml($color); |
|
142 | 142 | } |
143 | 143 | |
144 | -function replaceSl (string $string): string |
|
144 | +function replaceSl(string $string): string |
|
145 | 145 | { |
146 | - return str_replace ('\\', '/', $string); |
|
146 | + return str_replace('\\', '/', $string); |
|
147 | 147 | } |
148 | 148 | |
149 | -function replaceSr (string $string): string |
|
149 | +function replaceSr(string $string): string |
|
150 | 150 | { |
151 | - return str_replace ('/', '\\', $string); |
|
151 | + return str_replace('/', '\\', $string); |
|
152 | 152 | } |
153 | 153 | |
154 | -function basenameNoExt (string $path): string |
|
154 | +function basenameNoExt(string $path): string |
|
155 | 155 | { |
156 | - return pathinfo ($path, PATHINFO_FILENAME); |
|
156 | + return pathinfo($path, PATHINFO_FILENAME); |
|
157 | 157 | } |
158 | 158 | |
159 | -function file_ext (string $path): string |
|
159 | +function file_ext(string $path): string |
|
160 | 160 | { |
161 | - return strtolower (pathinfo ($path, PATHINFO_EXTENSION)); |
|
161 | + return strtolower(pathinfo($path, PATHINFO_EXTENSION)); |
|
162 | 162 | } |
163 | 163 | |
164 | -function filepathNoExt (string $path): string |
|
164 | +function filepathNoExt(string $path): string |
|
165 | 165 | { |
166 | - return dirname ($path) .'/'. basenameNoExt ($path); |
|
166 | + return dirname($path).'/'.basenameNoExt($path); |
|
167 | 167 | } |
168 | 168 | |
169 | -function array_first (array $array) |
|
169 | +function array_first(array $array) |
|
170 | 170 | { |
171 | - return array_shift ($array); |
|
171 | + return array_shift($array); |
|
172 | 172 | } |
173 | 173 | |
174 | -function array_end (array $array) |
|
174 | +function array_end(array $array) |
|
175 | 175 | { |
176 | - return array_pop ($array); |
|
176 | + return array_pop($array); |
|
177 | 177 | } |
178 | 178 | |
179 | -function substr_icount (string $haystack, string $needle, ...$params): int |
|
179 | +function substr_icount(string $haystack, string $needle, ...$params): int |
|
180 | 180 | { |
181 | - return substr_count (strtolower ($haystack), strtolower ($needle), ...$params); |
|
181 | + return substr_count(strtolower($haystack), strtolower($needle), ...$params); |
|
182 | 182 | } |
183 | 183 | |
184 | -function str_replace_assoc (string $subject, array $replacements): string |
|
184 | +function str_replace_assoc(string $subject, array $replacements): string |
|
185 | 185 | { |
186 | - return str_replace (array_keys ($replacements), array_values ($replacements), $subject); |
|
186 | + return str_replace(array_keys($replacements), array_values($replacements), $subject); |
|
187 | 187 | } |
188 | 188 | |
189 | -function pre (...$args): void |
|
189 | +function pre(...$args): void |
|
190 | 190 | { |
191 | - message (sizeof ($args) < 2 ? current ($args) : $args); |
|
191 | + message(sizeof($args) < 2 ? current ($args) : $args); |
|
192 | 192 | } |
193 | 193 | |
194 | -function messageBox (string $message, string $caption = '', ...$args) |
|
194 | +function messageBox(string $message, string $caption = '', ...$args) |
|
195 | 195 | { |
196 | - return (new MessageBox)->show ($message, $caption, ...$args); |
|
196 | + return (new MessageBox)->show($message, $caption, ...$args); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | class Components |
200 | 200 | { |
201 | 201 | static array $components = []; |
202 | 202 | |
203 | - public static function addComponent (int $selector, object $object): void |
|
203 | + public static function addComponent(int $selector, object $object): void |
|
204 | 204 | { |
205 | 205 | self::$components[$selector] = $object; |
206 | 206 | } |
207 | 207 | |
208 | - public static function getComponent (int $selector) |
|
208 | + public static function getComponent(int $selector) |
|
209 | 209 | { |
210 | 210 | return isset (self::$components[$selector]) ? |
211 | 211 | self::$components[$selector] : false; |
212 | 212 | } |
213 | 213 | |
214 | - public static function componentExists (int $selector): bool |
|
214 | + public static function componentExists(int $selector): bool |
|
215 | 215 | { |
216 | 216 | return isset (self::$components[$selector]); |
217 | 217 | } |
218 | 218 | |
219 | - public static function removeComponent (int $selector): void |
|
219 | + public static function removeComponent(int $selector): void |
|
220 | 220 | { |
221 | 221 | unset (self::$components[$selector]); |
222 | 222 | } |
223 | 223 | |
224 | - public static function cleanJunk (): void |
|
224 | + public static function cleanJunk(): void |
|
225 | 225 | { |
226 | 226 | // TODO: более строгие правила очистки мусорных объектов |
227 | 227 | |
@@ -229,46 +229,46 @@ discard block |
||
229 | 229 | { |
230 | 230 | try |
231 | 231 | { |
232 | - if ($object->getType ()->isSubclassOf (VoidEngine::objectType ('System.Windows.Forms.Form', 'System.Windows.Forms'))) |
|
232 | + if ($object->getType()->isSubclassOf(VoidEngine::objectType('System.Windows.Forms.Form', 'System.Windows.Forms'))) |
|
233 | 233 | continue; |
234 | 234 | } |
235 | 235 | |
236 | 236 | catch (\Exception $e) {} |
237 | 237 | |
238 | - VoidEngine::destructObject ($selector); |
|
238 | + VoidEngine::destructObject($selector); |
|
239 | 239 | |
240 | - if (!VoidEngine::objectExists ($selector)) |
|
240 | + if (!VoidEngine::objectExists($selector)) |
|
241 | 241 | unset (self::$components[$selector]); |
242 | 242 | } |
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | -function _c (int $selector) |
|
246 | +function _c(int $selector) |
|
247 | 247 | { |
248 | - return Components::getComponent ($selector); |
|
248 | + return Components::getComponent($selector); |
|
249 | 249 | } |
250 | 250 | |
251 | -function c ($name, bool $returnAllSimilarObjects = false) |
|
251 | +function c($name, bool $returnAllSimilarObjects = false) |
|
252 | 252 | { |
253 | - if (is_int ($name) && is_object ($object = _c ($name))) |
|
253 | + if (is_int($name) && is_object($object = _c($name))) |
|
254 | 254 | return $object; |
255 | 255 | |
256 | 256 | else |
257 | 257 | { |
258 | - $path = explode ('->', $name); |
|
258 | + $path = explode('->', $name); |
|
259 | 259 | $similar = []; |
260 | 260 | |
261 | 261 | foreach (Components::$components as $object) |
262 | 262 | try |
263 | 263 | { |
264 | - if ($object->name == end ($path)) |
|
264 | + if ($object->name == end($path)) |
|
265 | 265 | { |
266 | - if (sizeof ($path) > 1) |
|
266 | + if (sizeof($path) > 1) |
|
267 | 267 | try |
268 | 268 | { |
269 | - if (is_object ($parent = _c($object->parent->selector))) |
|
269 | + if (is_object($parent = _c($object->parent->selector))) |
|
270 | 270 | { |
271 | - if (c(join ('->', array_slice ($path, 0, -1))) == $parent) |
|
271 | + if (c(join('->', array_slice($path, 0, -1))) == $parent) |
|
272 | 272 | { |
273 | 273 | if ($returnAllSimilarObjects) |
274 | 274 | $similar[] = $object; |
@@ -302,18 +302,18 @@ discard block |
||
302 | 302 | continue; |
303 | 303 | } |
304 | 304 | |
305 | - if (sizeof ($path) == 2) |
|
305 | + if (sizeof($path) == 2) |
|
306 | 306 | { |
307 | 307 | $objects = c($path[1], true); |
308 | 308 | |
309 | - if (is_array ($objects)) |
|
309 | + if (is_array($objects)) |
|
310 | 310 | { |
311 | 311 | foreach ($objects as $id => $object) |
312 | 312 | try |
313 | 313 | { |
314 | - while (is_object ($parent = _c($object->parent->selector))) |
|
314 | + while (is_object($parent = _c($object->parent->selector))) |
|
315 | 315 | { |
316 | - if ($parent->getType ()->isSubclassOf (VoidEngine::objectType ('System.Windows.Forms.Form', 'System.Windows.Forms')) && $parent->name == $path[0]) |
|
316 | + if ($parent->getType()->isSubclassOf(VoidEngine::objectType('System.Windows.Forms.Form', 'System.Windows.Forms')) && $parent->name == $path[0]) |
|
317 | 317 | return $objects[$id]; |
318 | 318 | |
319 | 319 | else $object = $parent; |
@@ -331,70 +331,70 @@ discard block |
||
331 | 331 | else return false; |
332 | 332 | } |
333 | 333 | |
334 | - else return $returnAllSimilarObjects && sizeof ($similar) > 0 ? |
|
334 | + else return $returnAllSimilarObjects && sizeof($similar) > 0 ? |
|
335 | 335 | $similar : false; |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | -function setTimer (int $interval, callable $function): Timer |
|
339 | +function setTimer(int $interval, callable $function): Timer |
|
340 | 340 | { |
341 | 341 | $timer = new Timer; |
342 | 342 | $timer->interval = $interval; |
343 | 343 | |
344 | - $timer->tickEvent = function ($self) use ($function) |
|
344 | + $timer->tickEvent = function($self) use ($function) |
|
345 | 345 | { |
346 | - call_user_func ($function, $self); |
|
346 | + call_user_func($function, $self); |
|
347 | 347 | }; |
348 | 348 | |
349 | - $timer->start (); |
|
349 | + $timer->start(); |
|
350 | 350 | |
351 | 351 | return $timer; |
352 | 352 | } |
353 | 353 | |
354 | 354 | // FIXME: выполняется несколько раз, а не единожды |
355 | -function setTimeout (int $timeout, callable $function): Timer |
|
355 | +function setTimeout(int $timeout, callable $function): Timer |
|
356 | 356 | { |
357 | 357 | $timer = new Timer; |
358 | 358 | $timer->interval = $timeout; |
359 | 359 | |
360 | - $timer->tickEvent = function ($self) use ($function) |
|
360 | + $timer->tickEvent = function($self) use ($function) |
|
361 | 361 | { |
362 | - call_user_func ($function, $self); |
|
362 | + call_user_func($function, $self); |
|
363 | 363 | |
364 | - $self->stop (); |
|
364 | + $self->stop(); |
|
365 | 365 | }; |
366 | 366 | |
367 | - $timer->start (); |
|
367 | + $timer->start(); |
|
368 | 368 | |
369 | 369 | return $timer; |
370 | 370 | } |
371 | 371 | |
372 | 372 | class Clipboard |
373 | 373 | { |
374 | - public static function getText () |
|
374 | + public static function getText() |
|
375 | 375 | { |
376 | - return (new WFClass ('System.Windows.Forms.Clipboard'))->getText (); |
|
376 | + return (new WFClass('System.Windows.Forms.Clipboard'))->getText(); |
|
377 | 377 | } |
378 | 378 | |
379 | - public static function setText (string $text): void |
|
379 | + public static function setText(string $text): void |
|
380 | 380 | { |
381 | - (new WFClass ('System.Windows.Forms.Clipboard'))->setText ($text); |
|
381 | + (new WFClass('System.Windows.Forms.Clipboard'))->setText($text); |
|
382 | 382 | } |
383 | 383 | |
384 | - public static function getFiles (): array |
|
384 | + public static function getFiles(): array |
|
385 | 385 | { |
386 | - return (new WFClass ('System.Windows.Forms.Clipboard'))->getFileDropList ()->list; |
|
386 | + return (new WFClass('System.Windows.Forms.Clipboard'))->getFileDropList()->list; |
|
387 | 387 | } |
388 | 388 | |
389 | - public static function setFiles (array $files): void |
|
389 | + public static function setFiles(array $files): void |
|
390 | 390 | { |
391 | - $collection = new WFObject ('System.Collections.Specialized.StringCollection'); |
|
391 | + $collection = new WFObject('System.Collections.Specialized.StringCollection'); |
|
392 | 392 | |
393 | 393 | foreach ($files as $file) |
394 | - $collection->add ((string) $file); |
|
394 | + $collection->add((string) $file); |
|
395 | 395 | |
396 | - (new WFClass ('System.Windows.Forms.Clipboard'))->setFileDropList ($collection); |
|
397 | - VoidEngine::removeObjects ($collection->selector); |
|
396 | + (new WFClass('System.Windows.Forms.Clipboard'))->setFileDropList($collection); |
|
397 | + VoidEngine::removeObjects($collection->selector); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -402,14 +402,13 @@ discard block |
||
402 | 402 | { |
403 | 403 | protected $cursor; |
404 | 404 | |
405 | - public function __construct (int $handle = null) |
|
405 | + public function __construct(int $handle = null) |
|
406 | 406 | { |
407 | 407 | $handle !== null ? |
408 | - $this->cursor = new WFObject ('System.Windows.Forms.Cursor', false, $handle) : |
|
409 | - $this->cursor = new WFClass ('System.Windows.Forms.Cursor'); |
|
408 | + $this->cursor = new WFObject('System.Windows.Forms.Cursor', false, $handle) : $this->cursor = new WFClass('System.Windows.Forms.Cursor'); |
|
410 | 409 | } |
411 | 410 | |
412 | - public function getPosition (): array |
|
411 | + public function getPosition(): array |
|
413 | 412 | { |
414 | 413 | $pos = $this->cursor->position; |
415 | 414 | |
@@ -420,22 +419,22 @@ discard block |
||
420 | 419 | } |
421 | 420 | } |
422 | 421 | |
423 | -function get_cursor_x (int $handle = null): int |
|
422 | +function get_cursor_x(int $handle = null): int |
|
424 | 423 | { |
425 | - return (new Cursor ($handle))->getPosition ()[0]; |
|
424 | + return (new Cursor($handle))->getPosition()[0]; |
|
426 | 425 | } |
427 | 426 | |
428 | -function get_cursor_y (int $handle = null): int |
|
427 | +function get_cursor_y(int $handle = null): int |
|
429 | 428 | { |
430 | - return (new Cursor ($handle))->getPosition ()[1]; |
|
429 | + return (new Cursor($handle))->getPosition()[1]; |
|
431 | 430 | } |
432 | 431 | |
433 | -function get_cursor_pos (int $handle = null): array |
|
432 | +function get_cursor_pos(int $handle = null): array |
|
434 | 433 | { |
435 | - return (new Cursor ($handle))->getPosition (); |
|
434 | + return (new Cursor($handle))->getPosition(); |
|
436 | 435 | } |
437 | 436 | |
438 | -set_error_handler (function ($no, $str, $file, $line) |
|
437 | +set_error_handler(function($no, $str, $file, $line) |
|
439 | 438 | { |
440 | 439 | // Мог ли я здесь сделать более адекватный код с использованием pow/sqrt? Да, мог |
441 | 440 | // Почему не сделал? Скорость важнее |
@@ -458,7 +457,7 @@ discard block |
||
458 | 457 | ]; |
459 | 458 | |
460 | 459 | if ($GLOBALS['__debug']['error_status']) |
461 | - message ([ |
|
460 | + message([ |
|
462 | 461 | 'type' => $errarr[$no], |
463 | 462 | 'text' => $str, |
464 | 463 | 'file' => $file, |
@@ -6,8 +6,9 @@ discard block |
||
6 | 6 | { |
7 | 7 | $oldStatus = $GLOBALS['__debug']['error_status']; |
8 | 8 | |
9 | - if ($status !== null) |
|
10 | - $GLOBALS['__debug']['error_status'] = $status; |
|
9 | + if ($status !== null) { |
|
10 | + $GLOBALS['__debug']['error_status'] = $status; |
|
11 | + } |
|
11 | 12 | |
12 | 13 | return $oldStatus; |
13 | 14 | } |
@@ -41,9 +42,7 @@ discard block |
||
41 | 42 | try |
42 | 43 | { |
43 | 44 | eval ('return; '. $code); |
44 | - } |
|
45 | - |
|
46 | - catch (\Throwable $e) |
|
45 | + } catch (\Throwable $e) |
|
47 | 46 | { |
48 | 47 | return [ |
49 | 48 | 'text' => $e->getMessage (), |
@@ -67,9 +66,7 @@ discard block |
||
67 | 66 | try |
68 | 67 | { |
69 | 68 | return VoidEngine::callMethod (VoidEngine::createClass ('System.Enum',''), ['parse', 'object'], VoidEngine::objectType ($baseType), $value, true); |
70 | - } |
|
71 | - |
|
72 | - catch (\WinFormsException $e) |
|
69 | + } catch (\WinFormsException $e) |
|
73 | 70 | { |
74 | 71 | return (new WFClass ($baseType))->$value; |
75 | 72 | } |
@@ -80,34 +77,39 @@ discard block |
||
80 | 77 | $array = (new WFClass ('System.Array', null)) |
81 | 78 | ->createInstance (VoidEngine::objectType ($type), $size = sizeof ($items)); |
82 | 79 | |
83 | - for ($i = 0; $i < $size; ++$i) |
|
84 | - $array[$i] = array_shift ($items); |
|
80 | + for ($i = 0; $i < $size; ++$i) { |
|
81 | + $array[$i] = array_shift ($items); |
|
82 | + } |
|
85 | 83 | |
86 | 84 | return $array; |
87 | 85 | } |
88 | 86 | |
89 | 87 | function dir_create (string $path, int $mode = 0777): void |
90 | 88 | { |
91 | - if (!is_dir ($path)) |
|
92 | - mkdir ($path, $mode, true); |
|
93 | -} |
|
89 | + if (!is_dir ($path)) { |
|
90 | + mkdir ($path, $mode, true); |
|
91 | + } |
|
92 | + } |
|
94 | 93 | |
95 | 94 | function dir_delete (string $path): bool |
96 | 95 | { |
97 | - if (!is_dir ($path)) |
|
98 | - return false; |
|
96 | + if (!is_dir ($path)) { |
|
97 | + return false; |
|
98 | + } |
|
99 | 99 | |
100 | - foreach (array_slice (scandir ($path), 2) as $file) |
|
101 | - if (is_dir ($file = $path .'/'. $file)) |
|
100 | + foreach (array_slice (scandir ($path), 2) as $file) { |
|
101 | + if (is_dir ($file = $path .'/'. $file)) |
|
102 | 102 | { |
103 | 103 | dir_delete ($file); |
104 | + } |
|
104 | 105 | |
105 | - if (is_dir ($file)) |
|
106 | - rmdir ($file); |
|
106 | + if (is_dir ($file)) { |
|
107 | + rmdir ($file); |
|
108 | + } |
|
109 | + } else { |
|
110 | + unlink ($file); |
|
107 | 111 | } |
108 | 112 | |
109 | - else unlink ($file); |
|
110 | - |
|
111 | 113 | rmdir ($path); |
112 | 114 | |
113 | 115 | return true; |
@@ -121,17 +123,22 @@ discard block |
||
121 | 123 | |
122 | 124 | function dir_copy (string $from, string $to): bool |
123 | 125 | { |
124 | - if (!is_dir ($from)) |
|
125 | - return false; |
|
126 | + if (!is_dir ($from)) { |
|
127 | + return false; |
|
128 | + } |
|
126 | 129 | |
127 | - if (!is_dir ($to)) |
|
128 | - dir_create ($to); |
|
130 | + if (!is_dir ($to)) { |
|
131 | + dir_create ($to); |
|
132 | + } |
|
129 | 133 | |
130 | - foreach (array_slice (scandir ($from), 2) as $file) |
|
131 | - if (is_dir ($f = $from .'/'. $file)) |
|
134 | + foreach (array_slice (scandir ($from), 2) as $file) { |
|
135 | + if (is_dir ($f = $from .'/'. $file)) |
|
132 | 136 | dir_copy ($f, $to .'/'. $file); |
137 | + } |
|
133 | 138 | |
134 | - else copy ($f, $to .'/'. $file); |
|
139 | + else { |
|
140 | + copy ($f, $to .'/'. $file); |
|
141 | + } |
|
135 | 142 | |
136 | 143 | return true; |
137 | 144 | } |
@@ -229,16 +236,16 @@ discard block |
||
229 | 236 | { |
230 | 237 | try |
231 | 238 | { |
232 | - if ($object->getType ()->isSubclassOf (VoidEngine::objectType ('System.Windows.Forms.Form', 'System.Windows.Forms'))) |
|
233 | - continue; |
|
234 | - } |
|
235 | - |
|
236 | - catch (\Exception $e) {} |
|
239 | + if ($object->getType ()->isSubclassOf (VoidEngine::objectType ('System.Windows.Forms.Form', 'System.Windows.Forms'))) { |
|
240 | + continue; |
|
241 | + } |
|
242 | + } catch (\Exception $e) {} |
|
237 | 243 | |
238 | 244 | VoidEngine::destructObject ($selector); |
239 | 245 | |
240 | - if (!VoidEngine::objectExists ($selector)) |
|
241 | - unset (self::$components[$selector]); |
|
246 | + if (!VoidEngine::objectExists ($selector)) { |
|
247 | + unset (self::$components[$selector]); |
|
248 | + } |
|
242 | 249 | } |
243 | 250 | } |
244 | 251 | } |
@@ -250,16 +257,15 @@ discard block |
||
250 | 257 | |
251 | 258 | function c ($name, bool $returnAllSimilarObjects = false) |
252 | 259 | { |
253 | - if (is_int ($name) && is_object ($object = _c ($name))) |
|
254 | - return $object; |
|
255 | - |
|
256 | - else |
|
260 | + if (is_int ($name) && is_object ($object = _c ($name))) { |
|
261 | + return $object; |
|
262 | + } else |
|
257 | 263 | { |
258 | 264 | $path = explode ('->', $name); |
259 | 265 | $similar = []; |
260 | 266 | |
261 | - foreach (Components::$components as $object) |
|
262 | - try |
|
267 | + foreach (Components::$components as $object) { |
|
268 | + try |
|
263 | 269 | { |
264 | 270 | if ($object->name == end ($path)) |
265 | 271 | { |
@@ -272,32 +278,30 @@ discard block |
||
272 | 278 | { |
273 | 279 | if ($returnAllSimilarObjects) |
274 | 280 | $similar[] = $object; |
281 | + } |
|
275 | 282 | |
276 | - else return $object; |
|
283 | + else { |
|
284 | + return $object; |
|
285 | + } |
|
286 | + } else { |
|
287 | + continue; |
|
277 | 288 | } |
278 | - |
|
279 | - else continue; |
|
289 | + } else { |
|
290 | + continue; |
|
280 | 291 | } |
281 | - |
|
282 | - else continue; |
|
283 | - } |
|
284 | - |
|
285 | - catch (\Throwable $e) |
|
292 | + } catch (\Throwable $e) |
|
286 | 293 | { |
287 | 294 | continue; |
288 | - } |
|
289 | - |
|
290 | - else |
|
295 | + } else |
|
291 | 296 | { |
292 | - if ($returnAllSimilarObjects) |
|
293 | - $similar[] = $object; |
|
294 | - |
|
295 | - else return $object; |
|
297 | + if ($returnAllSimilarObjects) { |
|
298 | + $similar[] = $object; |
|
299 | + } else { |
|
300 | + return $object; |
|
301 | + } |
|
296 | 302 | } |
297 | 303 | } |
298 | - } |
|
299 | - |
|
300 | - catch (\Exception $e) |
|
304 | + } catch (\Exception $e) |
|
301 | 305 | { |
302 | 306 | continue; |
303 | 307 | } |
@@ -308,31 +312,32 @@ discard block |
||
308 | 312 | |
309 | 313 | if (is_array ($objects)) |
310 | 314 | { |
311 | - foreach ($objects as $id => $object) |
|
312 | - try |
|
315 | + foreach ($objects as $id => $object) { |
|
316 | + try |
|
313 | 317 | { |
314 | 318 | while (is_object ($parent = _c($object->parent->selector))) |
315 | 319 | { |
316 | 320 | if ($parent->getType ()->isSubclassOf (VoidEngine::objectType ('System.Windows.Forms.Form', 'System.Windows.Forms')) && $parent->name == $path[0]) |
317 | 321 | return $objects[$id]; |
322 | + } |
|
318 | 323 | |
319 | - else $object = $parent; |
|
324 | + else { |
|
325 | + $object = $parent; |
|
326 | + } |
|
320 | 327 | } |
321 | - } |
|
322 | - |
|
323 | - catch (\Throwable $e) |
|
328 | + } catch (\Throwable $e) |
|
324 | 329 | { |
325 | 330 | continue; |
326 | 331 | } |
327 | 332 | |
328 | 333 | return false; |
334 | + } else { |
|
335 | + return false; |
|
329 | 336 | } |
330 | - |
|
331 | - else return false; |
|
332 | - } |
|
333 | - |
|
334 | - else return $returnAllSimilarObjects && sizeof ($similar) > 0 ? |
|
337 | + } else { |
|
338 | + return $returnAllSimilarObjects && sizeof ($similar) > 0 ? |
|
335 | 339 | $similar : false; |
340 | + } |
|
336 | 341 | } |
337 | 342 | } |
338 | 343 | |
@@ -390,8 +395,9 @@ discard block |
||
390 | 395 | { |
391 | 396 | $collection = new WFObject ('System.Collections.Specialized.StringCollection'); |
392 | 397 | |
393 | - foreach ($files as $file) |
|
394 | - $collection->add ((string) $file); |
|
398 | + foreach ($files as $file) { |
|
399 | + $collection->add ((string) $file); |
|
400 | + } |
|
395 | 401 | |
396 | 402 | (new WFClass ('System.Windows.Forms.Clipboard'))->setFileDropList ($collection); |
397 | 403 | VoidEngine::removeObjects ($collection->selector); |
@@ -457,11 +463,12 @@ discard block |
||
457 | 463 | 16384 => 'E_USER_DEPRECATED' |
458 | 464 | ]; |
459 | 465 | |
460 | - if ($GLOBALS['__debug']['error_status']) |
|
461 | - message ([ |
|
466 | + if ($GLOBALS['__debug']['error_status']) { |
|
467 | + message ([ |
|
462 | 468 | 'type' => $errarr[$no], |
463 | 469 | 'text' => $str, |
464 | 470 | 'file' => $file, |
465 | 471 | 'line' => $line |
466 | 472 | ], 'PHP Script Error'); |
467 | -}); |
|
473 | + } |
|
474 | + }); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | { |
7 | 7 | public $class = 'System.Windows.Forms.TreeView'; |
8 | 8 | |
9 | - public function get_path () |
|
9 | + public function get_path() |
|
10 | 10 | { |
11 | 11 | try |
12 | 12 | { |
@@ -26,15 +26,15 @@ discard block |
||
26 | 26 | { |
27 | 27 | public $class = 'System.Windows.Forms.TreeNode'; |
28 | 28 | |
29 | - public function __construct (string $text = '') |
|
29 | + public function __construct(string $text = '') |
|
30 | 30 | { |
31 | - parent::__construct (null, $this->class); |
|
31 | + parent::__construct(null, $this->class); |
|
32 | 32 | |
33 | 33 | $this->text = $text; |
34 | 34 | } |
35 | 35 | |
36 | - public function get_path () |
|
36 | + public function get_path() |
|
37 | 37 | { |
38 | - return $this->getProperty ('FullPath'); |
|
38 | + return $this->getProperty('FullPath'); |
|
39 | 39 | } |
40 | 40 | } |
@@ -11,9 +11,7 @@ |
||
11 | 11 | try |
12 | 12 | { |
13 | 13 | $node = $this->selectedNode; |
14 | - } |
|
15 | - |
|
16 | - catch (\WinFormsException $e) |
|
14 | + } catch (\WinFormsException $e) |
|
17 | 15 | { |
18 | 16 | return false; |
19 | 17 | } |
@@ -4,48 +4,48 @@ |
||
4 | 4 | |
5 | 5 | class PictureBox extends Control |
6 | 6 | { |
7 | - public $class = 'System.Windows.Forms.PictureBox'; |
|
7 | + public $class = 'System.Windows.Forms.PictureBox'; |
|
8 | 8 | |
9 | - protected $image; |
|
9 | + protected $image; |
|
10 | 10 | |
11 | - public function __construct (Component $parent = null) |
|
12 | - { |
|
11 | + public function __construct (Component $parent = null) |
|
12 | + { |
|
13 | 13 | parent::__construct ($parent, $this->class); |
14 | 14 | |
15 | - $this->image = new PictureBoxImage ($this->selector); |
|
16 | - } |
|
15 | + $this->image = new PictureBoxImage ($this->selector); |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | class PictureBoxImage |
20 | 20 | { |
21 | - protected $selector; |
|
21 | + protected $selector; |
|
22 | 22 | protected $pictureBoxSelector; |
23 | 23 | protected $clipboard; |
24 | 24 | |
25 | - public function __construct (int $pictureBoxSelector) |
|
26 | - { |
|
27 | - $this->pictureBoxSelector = $pictureBoxSelector; |
|
28 | - $this->selector = VoidEngine::getProperty ($pictureBoxSelector, 'Image'); |
|
29 | - $this->clipboard = new WFClass ('System.Windows.Forms.Clipboard'); |
|
30 | - } |
|
25 | + public function __construct (int $pictureBoxSelector) |
|
26 | + { |
|
27 | + $this->pictureBoxSelector = $pictureBoxSelector; |
|
28 | + $this->selector = VoidEngine::getProperty ($pictureBoxSelector, 'Image'); |
|
29 | + $this->clipboard = new WFClass ('System.Windows.Forms.Clipboard'); |
|
30 | + } |
|
31 | 31 | |
32 | - public function loadFromFile (string $file) |
|
33 | - { |
|
32 | + public function loadFromFile (string $file) |
|
33 | + { |
|
34 | 34 | VoidEngine::setProperty ($this->pictureBoxSelector, 'Image', (new Image ())->loadFromFile ($file)->selector); |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - public function saveToFile (string $file) |
|
38 | - { |
|
39 | - VoidEngine::callMethod ($this->selector, 'Save', $file); |
|
40 | - } |
|
37 | + public function saveToFile (string $file) |
|
38 | + { |
|
39 | + VoidEngine::callMethod ($this->selector, 'Save', $file); |
|
40 | + } |
|
41 | 41 | |
42 | - public function loadFromClipboard () |
|
43 | - { |
|
44 | - VoidEngine::setProperty ($this->pictureBoxSelector, 'Image', $this->clipboard->getImage ()); |
|
45 | - } |
|
42 | + public function loadFromClipboard () |
|
43 | + { |
|
44 | + VoidEngine::setProperty ($this->pictureBoxSelector, 'Image', $this->clipboard->getImage ()); |
|
45 | + } |
|
46 | 46 | |
47 | - public function saveToClipboard () |
|
48 | - { |
|
49 | - $this->clipboard->setImage (VoidEngine::getProperty ($this->pictureBoxSelector, 'Image')); |
|
50 | - } |
|
47 | + public function saveToClipboard () |
|
48 | + { |
|
49 | + $this->clipboard->setImage (VoidEngine::getProperty ($this->pictureBoxSelector, 'Image')); |
|
50 | + } |
|
51 | 51 | } |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | |
9 | 9 | protected $image; |
10 | 10 | |
11 | - public function __construct (Component $parent = null) |
|
11 | + public function __construct(Component $parent = null) |
|
12 | 12 | { |
13 | - parent::__construct ($parent, $this->class); |
|
13 | + parent::__construct($parent, $this->class); |
|
14 | 14 | |
15 | - $this->image = new PictureBoxImage ($this->selector); |
|
15 | + $this->image = new PictureBoxImage($this->selector); |
|
16 | 16 | } |
17 | 17 | } |
18 | 18 | |
@@ -22,30 +22,30 @@ discard block |
||
22 | 22 | protected $pictureBoxSelector; |
23 | 23 | protected $clipboard; |
24 | 24 | |
25 | - public function __construct (int $pictureBoxSelector) |
|
25 | + public function __construct(int $pictureBoxSelector) |
|
26 | 26 | { |
27 | 27 | $this->pictureBoxSelector = $pictureBoxSelector; |
28 | - $this->selector = VoidEngine::getProperty ($pictureBoxSelector, 'Image'); |
|
29 | - $this->clipboard = new WFClass ('System.Windows.Forms.Clipboard'); |
|
28 | + $this->selector = VoidEngine::getProperty($pictureBoxSelector, 'Image'); |
|
29 | + $this->clipboard = new WFClass('System.Windows.Forms.Clipboard'); |
|
30 | 30 | } |
31 | 31 | |
32 | - public function loadFromFile (string $file) |
|
32 | + public function loadFromFile(string $file) |
|
33 | 33 | { |
34 | - VoidEngine::setProperty ($this->pictureBoxSelector, 'Image', (new Image ())->loadFromFile ($file)->selector); |
|
34 | + VoidEngine::setProperty($this->pictureBoxSelector, 'Image', (new Image())->loadFromFile($file)->selector); |
|
35 | 35 | } |
36 | 36 | |
37 | - public function saveToFile (string $file) |
|
37 | + public function saveToFile(string $file) |
|
38 | 38 | { |
39 | - VoidEngine::callMethod ($this->selector, 'Save', $file); |
|
39 | + VoidEngine::callMethod($this->selector, 'Save', $file); |
|
40 | 40 | } |
41 | 41 | |
42 | - public function loadFromClipboard () |
|
42 | + public function loadFromClipboard() |
|
43 | 43 | { |
44 | - VoidEngine::setProperty ($this->pictureBoxSelector, 'Image', $this->clipboard->getImage ()); |
|
44 | + VoidEngine::setProperty($this->pictureBoxSelector, 'Image', $this->clipboard->getImage()); |
|
45 | 45 | } |
46 | 46 | |
47 | - public function saveToClipboard () |
|
47 | + public function saveToClipboard() |
|
48 | 48 | { |
49 | - $this->clipboard->setImage (VoidEngine::getProperty ($this->pictureBoxSelector, 'Image')); |
|
49 | + $this->clipboard->setImage(VoidEngine::getProperty($this->pictureBoxSelector, 'Image')); |
|
50 | 50 | } |
51 | 51 | } |
@@ -4,28 +4,28 @@ |
||
4 | 4 | |
5 | 5 | class Process extends Component |
6 | 6 | { |
7 | - public $class = 'System.Diagnostics.Process'; |
|
8 | - public $namespace = 'System'; |
|
7 | + public $class = 'System.Diagnostics.Process'; |
|
8 | + public $namespace = 'System'; |
|
9 | 9 | |
10 | - public function __construct (int $pid = null) |
|
11 | - { |
|
10 | + public function __construct (int $pid = null) |
|
11 | + { |
|
12 | 12 | $this->selector = VoidEngine::createClass ($this->class, $this->namespace); |
13 | 13 | |
14 | - if ($pid !== null) |
|
14 | + if ($pid !== null) |
|
15 | 15 | $this->selector = $pid == getmypid () ? |
16 | 16 | VoidEngine::callMethod ($this->selector, 'GetCurrentProcess') : |
17 | 17 | VoidEngine::callMethod ($this->selector, 'GetProcessById', $pid); |
18 | 18 | |
19 | - Components::addComponent ($this->selector, $this); |
|
20 | - } |
|
19 | + Components::addComponent ($this->selector, $this); |
|
20 | + } |
|
21 | 21 | |
22 | - public static function getProcessById (int $pid) |
|
23 | - { |
|
24 | - return new self ($pid); |
|
25 | - } |
|
22 | + public static function getProcessById (int $pid) |
|
23 | + { |
|
24 | + return new self ($pid); |
|
25 | + } |
|
26 | 26 | |
27 | - public static function getCurrentProcess () |
|
28 | - { |
|
29 | - return new self (getmypid ()); |
|
30 | - } |
|
27 | + public static function getCurrentProcess () |
|
28 | + { |
|
29 | + return new self (getmypid ()); |
|
30 | + } |
|
31 | 31 | } |
@@ -4,28 +4,27 @@ |
||
4 | 4 | |
5 | 5 | class Process extends Component |
6 | 6 | { |
7 | - public $class = 'System.Diagnostics.Process'; |
|
7 | + public $class = 'System.Diagnostics.Process'; |
|
8 | 8 | public $namespace = 'System'; |
9 | 9 | |
10 | - public function __construct (int $pid = null) |
|
10 | + public function __construct(int $pid = null) |
|
11 | 11 | { |
12 | - $this->selector = VoidEngine::createClass ($this->class, $this->namespace); |
|
12 | + $this->selector = VoidEngine::createClass($this->class, $this->namespace); |
|
13 | 13 | |
14 | 14 | if ($pid !== null) |
15 | - $this->selector = $pid == getmypid () ? |
|
16 | - VoidEngine::callMethod ($this->selector, 'GetCurrentProcess') : |
|
17 | - VoidEngine::callMethod ($this->selector, 'GetProcessById', $pid); |
|
15 | + $this->selector = $pid == getmypid() ? |
|
16 | + VoidEngine::callMethod($this->selector, 'GetCurrentProcess') : VoidEngine::callMethod($this->selector, 'GetProcessById', $pid); |
|
18 | 17 | |
19 | - Components::addComponent ($this->selector, $this); |
|
18 | + Components::addComponent($this->selector, $this); |
|
20 | 19 | } |
21 | 20 | |
22 | - public static function getProcessById (int $pid) |
|
21 | + public static function getProcessById(int $pid) |
|
23 | 22 | { |
24 | - return new self ($pid); |
|
23 | + return new self($pid); |
|
25 | 24 | } |
26 | 25 | |
27 | - public static function getCurrentProcess () |
|
26 | + public static function getCurrentProcess() |
|
28 | 27 | { |
29 | - return new self (getmypid ()); |
|
28 | + return new self(getmypid()); |
|
30 | 29 | } |
31 | 30 | } |
@@ -11,10 +11,11 @@ |
||
11 | 11 | { |
12 | 12 | $this->selector = VoidEngine::createClass ($this->class, $this->namespace); |
13 | 13 | |
14 | - if ($pid !== null) |
|
15 | - $this->selector = $pid == getmypid () ? |
|
14 | + if ($pid !== null) { |
|
15 | + $this->selector = $pid == getmypid () ? |
|
16 | 16 | VoidEngine::callMethod ($this->selector, 'GetCurrentProcess') : |
17 | 17 | VoidEngine::callMethod ($this->selector, 'GetProcessById', $pid); |
18 | + } |
|
18 | 19 | |
19 | 20 | Components::addComponent ($this->selector, $this); |
20 | 21 | } |
@@ -105,7 +105,8 @@ |
||
105 | 105 | require 'components/FastColoredTextBox.php'; |
106 | 106 | require 'components/Scintilla.php'; |
107 | 107 | |
108 | -if (is_dir ('extensions')) |
|
108 | +if (is_dir ('extensions')) { |
|
109 | 109 | foreach (scandir ('extensions') as $ext) |
110 | 110 | if (is_dir ('extensions/'. $ext) && file_exists ($ext = 'extensions/'. $ext .'/main.php')) |
111 | 111 | require $ext; |
112 | +} |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | const ENGINE_VERSION = '3.5.5 build-2019/09/21'; |
37 | 37 | const ENGINE_DIR = __DIR__; |
38 | 38 | |
39 | -chdir (ENGINE_DIR); |
|
39 | +chdir(ENGINE_DIR); |
|
40 | 40 | |
41 | 41 | $GLOBALS['__debug'] = [ |
42 | - 'start_time' => microtime (true), |
|
42 | + 'start_time' => microtime(true), |
|
43 | 43 | 'error_status' => true |
44 | 44 | ]; |
45 | 45 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | require 'common/Others.php'; |
50 | 50 | require 'common/Events.php'; |
51 | 51 | |
52 | -define ('VoidEngine\CORE_VERSION', $APPLICATION->productVersion); |
|
52 | +define('VoidEngine\CORE_VERSION', $APPLICATION->productVersion); |
|
53 | 53 | |
54 | 54 | require 'components/Component.php'; |
55 | 55 | require 'components/Control.php'; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | require 'components/FastColoredTextBox.php'; |
97 | 97 | require 'components/Scintilla.php'; |
98 | 98 | |
99 | -if (is_dir ('extensions')) |
|
100 | - foreach (scandir ('extensions') as $ext) |
|
101 | - if (is_dir ('extensions/'. $ext) && file_exists ($ext = 'extensions/'. $ext .'/main.php')) |
|
99 | +if (is_dir('extensions')) |
|
100 | + foreach (scandir('extensions') as $ext) |
|
101 | + if (is_dir('extensions/'.$ext) && file_exists($ext = 'extensions/'.$ext.'/main.php')) |
|
102 | 102 | require $ext; |
@@ -7,9 +7,9 @@ discard block |
||
7 | 7 | public static function setObjectEvent (int $object, string $eventName, callable $function) |
8 | 8 | { |
9 | 9 | VoidEngine::setObjectEvent ($object, $eventName, function ($sender, ...$args) use ($function) |
10 | - { |
|
10 | + { |
|
11 | 11 | try |
12 | - { |
|
12 | + { |
|
13 | 13 | foreach ($args as $id => $arg) |
14 | 14 | $args[$id] = EngineAdditions::coupleSelector ($arg); |
15 | 15 | |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | $e : new WFObject ($sender), ...$args); |
18 | 18 | } |
19 | 19 | |
20 | - catch (\Throwable $e) |
|
21 | - { |
|
20 | + catch (\Throwable $e) |
|
21 | + { |
|
22 | 22 | message ([ |
23 | 23 | 'type' => get_class ($e), |
24 | 24 | 'text' => $e->getMessage (), |
@@ -4,35 +4,35 @@ |
||
4 | 4 | |
5 | 5 | class Events |
6 | 6 | { |
7 | - public static function setObjectEvent (int $object, string $eventName, callable $function) |
|
7 | + public static function setObjectEvent(int $object, string $eventName, callable $function) |
|
8 | 8 | { |
9 | - VoidEngine::setObjectEvent ($object, $eventName, function ($sender, ...$args) use ($function) |
|
9 | + VoidEngine::setObjectEvent($object, $eventName, function($sender, ...$args) use ($function) |
|
10 | 10 | { |
11 | 11 | try |
12 | 12 | { |
13 | 13 | foreach ($args as $id => $arg) |
14 | - $args[$id] = EngineAdditions::coupleSelector ($arg); |
|
14 | + $args[$id] = EngineAdditions::coupleSelector($arg); |
|
15 | 15 | |
16 | - return $function (($e = _c($sender)) !== false ? |
|
17 | - $e : new WFObject ($sender), ...$args); |
|
16 | + return $function(($e = _c($sender)) !== false ? |
|
17 | + $e : new WFObject($sender), ...$args); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | catch (\Throwable $e) |
21 | 21 | { |
22 | - message ([ |
|
23 | - 'type' => get_class ($e), |
|
24 | - 'text' => $e->getMessage (), |
|
25 | - 'file' => $e->getFile (), |
|
26 | - 'line' => $e->getLine (), |
|
27 | - 'code' => $e->getCode (), |
|
28 | - 'trace' => $e->getTraceAsString () |
|
22 | + message([ |
|
23 | + 'type' => get_class($e), |
|
24 | + 'text' => $e->getMessage(), |
|
25 | + 'file' => $e->getFile(), |
|
26 | + 'line' => $e->getLine(), |
|
27 | + 'code' => $e->getCode(), |
|
28 | + 'trace' => $e->getTraceAsString() |
|
29 | 29 | ], 'PHP Critical Error'); |
30 | 30 | } |
31 | 31 | }); |
32 | 32 | } |
33 | 33 | |
34 | - public static function removeObjectEvent (int $object, string $eventName) |
|
34 | + public static function removeObjectEvent(int $object, string $eventName) |
|
35 | 35 | { |
36 | - VoidEngine::removeObjectEvent ($object, $eventName); |
|
36 | + VoidEngine::removeObjectEvent($object, $eventName); |
|
37 | 37 | } |
38 | 38 | } |
@@ -10,14 +10,13 @@ |
||
10 | 10 | { |
11 | 11 | try |
12 | 12 | { |
13 | - foreach ($args as $id => $arg) |
|
14 | - $args[$id] = EngineAdditions::coupleSelector ($arg); |
|
13 | + foreach ($args as $id => $arg) { |
|
14 | + $args[$id] = EngineAdditions::coupleSelector ($arg); |
|
15 | + } |
|
15 | 16 | |
16 | 17 | return $function (($e = _c($sender)) !== false ? |
17 | 18 | $e : new WFObject ($sender), ...$args); |
18 | - } |
|
19 | - |
|
20 | - catch (\Throwable $e) |
|
19 | + } catch (\Throwable $e) |
|
21 | 20 | { |
22 | 21 | message ([ |
23 | 22 | 'type' => get_class ($e), |
@@ -42,7 +42,7 @@ |
||
42 | 42 | public string $name; // Имя объекта |
43 | 43 | public int $link; // АСД-ссылка на объект |
44 | 44 | |
45 | - public function __construct (string $name, int $link) |
|
45 | + public function __construct(string $name, int $link) |
|
46 | 46 | { |
47 | 47 | $this->name = $name; |
48 | 48 | $this->link = $link; |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * @return array - возвращает список созданных объектов |
21 | 21 | */ |
22 | 22 | |
23 | - public static function run ($syntaxTree, string $resourcesDir = null, array $parent = null): array |
|
23 | + public static function run($syntaxTree, string $resourcesDir = null, array $parent = null): array |
|
24 | 24 | { |
25 | 25 | if ($syntaxTree instanceof VLFParser) |
26 | 26 | $syntaxTree = $syntaxTree->tree; |
27 | 27 | |
28 | - elseif (!is_array ($syntaxTree) && self::$throw_errors) |
|
29 | - throw new \Exception ('$syntaxTree argument must be instance of VoidEngine\VLFParser or contains Abstract Syntax Tree - multi-dimensional array'); |
|
28 | + elseif (!is_array($syntaxTree) && self::$throw_errors) |
|
29 | + throw new \Exception('$syntaxTree argument must be instance of VoidEngine\VLFParser or contains Abstract Syntax Tree - multi-dimensional array'); |
|
30 | 30 | |
31 | 31 | foreach ($syntaxTree as $id => $syntaxInfo) |
32 | 32 | if (isset ($syntaxInfo['type'])) |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | $args = $syntaxInfo['info']['arguments']; |
44 | 44 | |
45 | 45 | foreach ($args as $arg_id => $arg) |
46 | - if (is_object ($arg) && $arg instanceof VLFLink) |
|
46 | + if (is_object($arg) && $arg instanceof VLFLink) |
|
47 | 47 | $args[$arg_id] = isset (self::$objects[$arg->name]) ? |
48 | - self::formatLine ($arg->name, self::$objects) : null; |
|
48 | + self::formatLine($arg->name, self::$objects) : null; |
|
49 | 49 | |
50 | - else $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
50 | + else $args[$arg_id] = self::formatLine($arg, self::$objects); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | try |
54 | 54 | { |
55 | - self::$objects[$name] = eval ("namespace VoidEngine; return new $class (". implode (', ', $args) .");"); |
|
55 | + self::$objects[$name] = eval ("namespace VoidEngine; return new $class (".implode(', ', $args).");"); |
|
56 | 56 | |
57 | 57 | try |
58 | 58 | { |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | catch (\Throwable $e) |
66 | 66 | { |
67 | 67 | if (self::$throw_errors) |
68 | - throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
68 | + throw new \Exception('Interpeter couldn\'t create object "'.$class.'" with name "'.$name.'" at line "'.$syntaxInfo['line'].'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
69 | 69 | } |
70 | 70 | break; |
71 | 71 | |
72 | 72 | case VLF_SUBOBJECT_DEFINITION: |
73 | - self::$objects = self::run ((new VLFParser ($syntaxInfo['info']['object_vlf_info']))->tree, null, $syntaxInfo); |
|
73 | + self::$objects = self::run((new VLFParser($syntaxInfo['info']['object_vlf_info']))->tree, null, $syntaxInfo); |
|
74 | 74 | break; |
75 | 75 | |
76 | 76 | case VLF_PROPERTY_SET: |
@@ -80,34 +80,34 @@ discard block |
||
80 | 80 | $propertyValue = $syntaxInfo['info']['property_value']; |
81 | 81 | $preset = ''; |
82 | 82 | |
83 | - if (is_object ($propertyValue) && $propertyValue instanceof VLFLink) |
|
83 | + if (is_object($propertyValue) && $propertyValue instanceof VLFLink) |
|
84 | 84 | $propertyValue = isset (self::$objects[$propertyValue->name]) ? |
85 | - self::formatLine ($propertyValue->name, self::$objects) : null; |
|
85 | + self::formatLine($propertyValue->name, self::$objects) : null; |
|
86 | 86 | |
87 | - elseif (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
87 | + elseif (preg_match('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
88 | 88 | { |
89 | - $use = substr ($propertyValue, strpos ($propertyValue, 'use')); |
|
90 | - $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
|
91 | - $use = explode (' ', $use); |
|
89 | + $use = substr($propertyValue, strpos($propertyValue, 'use')); |
|
90 | + $use = $ouse = substr($use, ($pos = strpos($use, '(') + 1), strpos($use, ')') - $pos); |
|
91 | + $use = explode(' ', $use); |
|
92 | 92 | |
93 | 93 | foreach ($use as $id => $useParam) |
94 | 94 | if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
95 | 95 | { |
96 | 96 | $fname = $use[$id + 1]; |
97 | 97 | |
98 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
99 | - $fname = substr ($fname, 0, -1); |
|
98 | + if (substr($fname, strlen($fname) - 1) == ',') |
|
99 | + $fname = substr($fname, 0, -1); |
|
100 | 100 | |
101 | 101 | $preset .= "$fname = $useParam; "; |
102 | 102 | |
103 | 103 | unset ($use[$id]); |
104 | 104 | } |
105 | 105 | |
106 | - $preset = self::formatLine ($preset, self::$objects); |
|
107 | - $propertyValue = self::formatLine (str_replace ($ouse, join (' ', $use), $propertyValue), self::$objects); |
|
106 | + $preset = self::formatLine($preset, self::$objects); |
|
107 | + $propertyValue = self::formatLine(str_replace($ouse, join(' ', $use), $propertyValue), self::$objects); |
|
108 | 108 | } |
109 | 109 | |
110 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
110 | + else $propertyValue = self::formatLine($propertyValue, self::$objects); |
|
111 | 111 | |
112 | 112 | try |
113 | 113 | { |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | { |
121 | 121 | $propertyValue = $syntaxInfo['info']['property_raw_value']; |
122 | 122 | |
123 | - if (strpos ($propertyName, '->') !== false) |
|
124 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
123 | + if (strpos($propertyName, '->') !== false) |
|
124 | + eval ('namespace VoidEngine; '.$preset.' _c('.self::$objects[$name]->selector.')->'.$propertyName.' = '.$propertyValue.';'); |
|
125 | 125 | |
126 | 126 | else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
127 | 127 | } |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | catch (\Throwable $e) |
130 | 130 | { |
131 | 131 | if (self::$throw_errors) |
132 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
132 | + throw new \Exception('Interpeter couldn\'t set property "'.$propertyName.'" with value "'.$propertyValue.'" at line "'.$syntaxInfo['line'].'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
137 | 137 | elseif (self::$throw_errors) |
138 | - throw new \Exception ('Setting property to an non-object at line "'. $syntaxInfo['line']); |
|
138 | + throw new \Exception('Setting property to an non-object at line "'.$syntaxInfo['line']); |
|
139 | 139 | break; |
140 | 140 | |
141 | 141 | case VLF_METHOD_CALL: |
@@ -145,61 +145,61 @@ discard block |
||
145 | 145 | $methodArgs = $syntaxInfo['info']['method_arguments']; |
146 | 146 | |
147 | 147 | foreach ($methodArgs as $arg_id => $arg) |
148 | - if (is_object ($arg) && $arg instanceof VLFLink) |
|
148 | + if (is_object($arg) && $arg instanceof VLFLink) |
|
149 | 149 | $methodArgs[$arg_id] = isset (self::$objects[$arg->name]) ? |
150 | - self::formatLine ($arg->name, self::$objects) : null; |
|
150 | + self::formatLine($arg->name, self::$objects) : null; |
|
151 | 151 | |
152 | - else $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
152 | + else $methodArgs[$arg_id] = self::formatLine($arg, self::$objects); |
|
153 | 153 | |
154 | 154 | try |
155 | 155 | { |
156 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
157 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
156 | + if (strpos($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
157 | + eval ('namespace VoidEngine; _c('.self::$objects[$name]->selector.')->'.$methodName.' ('.implode(', ', $methodArgs).');'); |
|
158 | 158 | |
159 | - elseif (sizeof ($methodArgs) > 0) |
|
160 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
159 | + elseif (sizeof($methodArgs) > 0) |
|
160 | + self::$objects[$name]->$methodName(...eval ('namespace VoidEngine; return ['.implode(', ', $methodArgs).'];')); |
|
161 | 161 | |
162 | - else self::$objects[$name]->$methodName (); |
|
162 | + else self::$objects[$name]->$methodName(); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | catch (\Throwable $e) |
166 | 166 | { |
167 | 167 | if (self::$throw_errors) |
168 | - throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
168 | + throw new \Exception('Interpeter couldn\'t call method "'.$methodName.'" with arguments '.json_encode($methodArgs).' at line "'.$syntaxInfo['line'].'". Exception info:'."\n\n".(string) $e, 0, $e); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | 172 | elseif (self::$throw_errors) |
173 | - throw new \Exception ('Calling method to an non-object at line "'. $syntaxInfo['line'] .'"'); |
|
173 | + throw new \Exception('Calling method to an non-object at line "'.$syntaxInfo['line'].'"'); |
|
174 | 174 | break; |
175 | 175 | |
176 | 176 | case VLF_RUNTIME_EXECUTABLE: |
177 | - eval (self::formatLine ($syntaxInfo['info']['code'], self::$objects)); |
|
177 | + eval (self::formatLine($syntaxInfo['info']['code'], self::$objects)); |
|
178 | 178 | break; |
179 | 179 | } |
180 | 180 | |
181 | - if (isset ($syntaxInfo['syntax_nodes']) && sizeof ($syntaxInfo['syntax_nodes']) > 0) |
|
182 | - self::$objects = self::run ($syntaxInfo['syntax_nodes'], null, $syntaxInfo); |
|
181 | + if (isset ($syntaxInfo['syntax_nodes']) && sizeof($syntaxInfo['syntax_nodes']) > 0) |
|
182 | + self::$objects = self::run($syntaxInfo['syntax_nodes'], null, $syntaxInfo); |
|
183 | 183 | } |
184 | 184 | |
185 | - else throw new \Exception ('Catched unknown syntax node: "'. json_encode ($syntaxInfo) .'"'); |
|
185 | + else throw new \Exception('Catched unknown syntax node: "'.json_encode($syntaxInfo).'"'); |
|
186 | 186 | |
187 | - if (is_dir ($resourcesDir)) |
|
188 | - foreach (glob ($resourcesDir .'/*.vrsf') as $id => $dir) |
|
187 | + if (is_dir($resourcesDir)) |
|
188 | + foreach (glob($resourcesDir.'/*.vrsf') as $id => $dir) |
|
189 | 189 | { |
190 | - $baseName = basenameNoExt ($dir); |
|
191 | - $info = explode ('.', $baseName); |
|
190 | + $baseName = basenameNoExt($dir); |
|
191 | + $info = explode('.', $baseName); |
|
192 | 192 | |
193 | 193 | if (isset (self::$objects[$info[0]])) |
194 | 194 | { |
195 | 195 | if (isset ($info[2])) |
196 | 196 | { |
197 | - $collection = VoidEngine::getProperty (self::$objects[$info[0]]->selector, $info[1]); |
|
197 | + $collection = VoidEngine::getProperty(self::$objects[$info[0]]->selector, $info[1]); |
|
198 | 198 | |
199 | - VoidEngine::callMethod ($collection, 'Add', [VoidEngine::importObject (base64_encode (file_get_contents ($dir))), 'object']); |
|
199 | + VoidEngine::callMethod($collection, 'Add', [VoidEngine::importObject(base64_encode(file_get_contents($dir))), 'object']); |
|
200 | 200 | } |
201 | 201 | |
202 | - else VoidEngine::setProperty (self::$objects[$info[0]]->selector, $info[1], VoidEngine::importObject (base64_encode (file_get_contents ($dir)))); |
|
202 | + else VoidEngine::setProperty(self::$objects[$info[0]]->selector, $info[1], VoidEngine::importObject(base64_encode(file_get_contents($dir)))); |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
@@ -216,26 +216,25 @@ discard block |
||
216 | 216 | * @return string - возвращает форматированную строку |
217 | 217 | */ |
218 | 218 | |
219 | - public static function formatLine (string $line, array $objects = []): string |
|
219 | + public static function formatLine(string $line, array $objects = []): string |
|
220 | 220 | { |
221 | - if (sizeof ($objects) > 0) |
|
221 | + if (sizeof($objects) > 0) |
|
222 | 222 | { |
223 | - $len = strlen ($line); |
|
223 | + $len = strlen($line); |
|
224 | 224 | $newLine = ''; |
225 | 225 | |
226 | - $replacement = array_map (function ($object) |
|
226 | + $replacement = array_map(function($object) |
|
227 | 227 | { |
228 | - return Components::componentExists ($object->selector) !== false ? |
|
229 | - '\VoidEngine\_c('. $object->selector .')' : |
|
230 | - 'unserialize (\''. serialize ($object) .'\')'; |
|
228 | + return Components::componentExists($object->selector) !== false ? |
|
229 | + '\VoidEngine\_c('.$object->selector.')' : 'unserialize (\''.serialize($object).'\')'; |
|
231 | 230 | }, $objects); |
232 | 231 | |
233 | - $replacement = array_map (function ($name) |
|
232 | + $replacement = array_map(function($name) |
|
234 | 233 | { |
235 | - return strlen ($name = trim ($name)) + substr_count ($name, '_'); |
|
236 | - }, $omap = array_flip ($replacement)); |
|
234 | + return strlen($name = trim($name)) + substr_count($name, '_'); |
|
235 | + }, $omap = array_flip($replacement)); |
|
237 | 236 | |
238 | - arsort ($replacement); |
|
237 | + arsort($replacement); |
|
239 | 238 | |
240 | 239 | $nReplacement = []; |
241 | 240 | |
@@ -243,14 +242,14 @@ discard block |
||
243 | 242 | $nReplacement[$omap[$replaceTo]] = $replaceTo; |
244 | 243 | |
245 | 244 | $replacement = $nReplacement; |
246 | - $blacklist = array_flip (['\'', '"', '$']); |
|
245 | + $blacklist = array_flip(['\'', '"', '$']); |
|
247 | 246 | |
248 | 247 | for ($i = 0; $i < $len; ++$i) |
249 | 248 | { |
250 | 249 | $replaced = false; |
251 | 250 | |
252 | 251 | foreach ($replacement as $name => $replaceAt) |
253 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
252 | + if (substr($line, $i, ($l = strlen($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
254 | 253 | { |
255 | 254 | $newLine .= $replaceAt; |
256 | 255 |
@@ -22,19 +22,20 @@ discard block |
||
22 | 22 | |
23 | 23 | public static function run ($syntaxTree, string $resourcesDir = null, array $parent = null): array |
24 | 24 | { |
25 | - if ($syntaxTree instanceof VLFParser) |
|
26 | - $syntaxTree = $syntaxTree->tree; |
|
27 | - |
|
28 | - elseif (!is_array ($syntaxTree) && self::$throw_errors) |
|
29 | - throw new \Exception ('$syntaxTree argument must be instance of VoidEngine\VLFParser or contains Abstract Syntax Tree - multi-dimensional array'); |
|
25 | + if ($syntaxTree instanceof VLFParser) { |
|
26 | + $syntaxTree = $syntaxTree->tree; |
|
27 | + } elseif (!is_array ($syntaxTree) && self::$throw_errors) { |
|
28 | + throw new \Exception ('$syntaxTree argument must be instance of VoidEngine\VLFParser or contains Abstract Syntax Tree - multi-dimensional array'); |
|
29 | + } |
|
30 | 30 | |
31 | - foreach ($syntaxTree as $id => $syntaxInfo) |
|
32 | - if (isset ($syntaxInfo['type'])) |
|
31 | + foreach ($syntaxTree as $id => $syntaxInfo) { |
|
32 | + if (isset ($syntaxInfo['type'])) |
|
33 | 33 | { |
34 | 34 | switch ($syntaxInfo['type']) |
35 | 35 | { |
36 | 36 | case VLF_OBJECT_DEFINITION: |
37 | 37 | $class = $syntaxInfo['info']['object_class']; |
38 | + } |
|
38 | 39 | $name = $syntaxInfo['info']['object_name']; |
39 | 40 | $args = []; |
40 | 41 | |
@@ -42,12 +43,15 @@ discard block |
||
42 | 43 | { |
43 | 44 | $args = $syntaxInfo['info']['arguments']; |
44 | 45 | |
45 | - foreach ($args as $arg_id => $arg) |
|
46 | - if (is_object ($arg) && $arg instanceof VLFLink) |
|
46 | + foreach ($args as $arg_id => $arg) { |
|
47 | + if (is_object ($arg) && $arg instanceof VLFLink) |
|
47 | 48 | $args[$arg_id] = isset (self::$objects[$arg->name]) ? |
48 | 49 | self::formatLine ($arg->name, self::$objects) : null; |
50 | + } |
|
49 | 51 | |
50 | - else $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
52 | + else { |
|
53 | + $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
54 | + } |
|
51 | 55 | } |
52 | 56 | |
53 | 57 | try |
@@ -57,15 +61,12 @@ discard block |
||
57 | 61 | try |
58 | 62 | { |
59 | 63 | self::$objects[$name]->name = $name; |
60 | - } |
|
61 | - |
|
62 | - catch (\Throwable $e) {} |
|
63 | - } |
|
64 | - |
|
65 | - catch (\Throwable $e) |
|
64 | + } catch (\Throwable $e) {} |
|
65 | + } catch (\Throwable $e) |
|
66 | 66 | { |
67 | - if (self::$throw_errors) |
|
68 | - throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
67 | + if (self::$throw_errors) { |
|
68 | + throw new \Exception ('Interpeter couldn\'t create object "'. $class .'" with name "'. $name .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
69 | + } |
|
69 | 70 | } |
70 | 71 | break; |
71 | 72 | |
@@ -80,23 +81,24 @@ discard block |
||
80 | 81 | $propertyValue = $syntaxInfo['info']['property_value']; |
81 | 82 | $preset = ''; |
82 | 83 | |
83 | - if (is_object ($propertyValue) && $propertyValue instanceof VLFLink) |
|
84 | - $propertyValue = isset (self::$objects[$propertyValue->name]) ? |
|
84 | + if (is_object ($propertyValue) && $propertyValue instanceof VLFLink) { |
|
85 | + $propertyValue = isset (self::$objects[$propertyValue->name]) ? |
|
85 | 86 | self::formatLine ($propertyValue->name, self::$objects) : null; |
86 | - |
|
87 | - elseif (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
87 | + } elseif (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
88 | 88 | { |
89 | 89 | $use = substr ($propertyValue, strpos ($propertyValue, 'use')); |
90 | 90 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
91 | 91 | $use = explode (' ', $use); |
92 | 92 | |
93 | - foreach ($use as $id => $useParam) |
|
94 | - if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
93 | + foreach ($use as $id => $useParam) { |
|
94 | + if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
95 | 95 | { |
96 | 96 | $fname = $use[$id + 1]; |
97 | + } |
|
97 | 98 | |
98 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
99 | - $fname = substr ($fname, 0, -1); |
|
99 | + if (substr ($fname, strlen ($fname) - 1) == ',') { |
|
100 | + $fname = substr ($fname, 0, -1); |
|
101 | + } |
|
100 | 102 | |
101 | 103 | $preset .= "$fname = $useParam; "; |
102 | 104 | |
@@ -105,37 +107,34 @@ discard block |
||
105 | 107 | |
106 | 108 | $preset = self::formatLine ($preset, self::$objects); |
107 | 109 | $propertyValue = self::formatLine (str_replace ($ouse, join (' ', $use), $propertyValue), self::$objects); |
110 | + } else { |
|
111 | + $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
108 | 112 | } |
109 | 113 | |
110 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
111 | - |
|
112 | 114 | try |
113 | 115 | { |
114 | 116 | self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
115 | - } |
|
116 | - |
|
117 | - catch (\Throwable $e) |
|
117 | + } catch (\Throwable $e) |
|
118 | 118 | { |
119 | 119 | try |
120 | 120 | { |
121 | 121 | $propertyValue = $syntaxInfo['info']['property_raw_value']; |
122 | 122 | |
123 | - if (strpos ($propertyName, '->') !== false) |
|
124 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
125 | - |
|
126 | - else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
127 | - } |
|
128 | - |
|
129 | - catch (\Throwable $e) |
|
123 | + if (strpos ($propertyName, '->') !== false) { |
|
124 | + eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
125 | + } else { |
|
126 | + self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
127 | + } |
|
128 | + } catch (\Throwable $e) |
|
130 | 129 | { |
131 | - if (self::$throw_errors) |
|
132 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
130 | + if (self::$throw_errors) { |
|
131 | + throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
132 | + } |
|
133 | 133 | } |
134 | 134 | } |
135 | + } elseif (self::$throw_errors) { |
|
136 | + throw new \Exception ('Setting property to an non-object at line "'. $syntaxInfo['line']); |
|
135 | 137 | } |
136 | - |
|
137 | - elseif (self::$throw_errors) |
|
138 | - throw new \Exception ('Setting property to an non-object at line "'. $syntaxInfo['line']); |
|
139 | 138 | break; |
140 | 139 | |
141 | 140 | case VLF_METHOD_CALL: |
@@ -144,33 +143,34 @@ discard block |
||
144 | 143 | $methodName = $syntaxInfo['info']['method_name']; |
145 | 144 | $methodArgs = $syntaxInfo['info']['method_arguments']; |
146 | 145 | |
147 | - foreach ($methodArgs as $arg_id => $arg) |
|
148 | - if (is_object ($arg) && $arg instanceof VLFLink) |
|
146 | + foreach ($methodArgs as $arg_id => $arg) { |
|
147 | + if (is_object ($arg) && $arg instanceof VLFLink) |
|
149 | 148 | $methodArgs[$arg_id] = isset (self::$objects[$arg->name]) ? |
150 | 149 | self::formatLine ($arg->name, self::$objects) : null; |
150 | + } |
|
151 | 151 | |
152 | - else $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
152 | + else { |
|
153 | + $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
154 | + } |
|
153 | 155 | |
154 | 156 | try |
155 | 157 | { |
156 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
157 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
158 | - |
|
159 | - elseif (sizeof ($methodArgs) > 0) |
|
160 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
161 | - |
|
162 | - else self::$objects[$name]->$methodName (); |
|
163 | - } |
|
164 | - |
|
165 | - catch (\Throwable $e) |
|
158 | + if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) { |
|
159 | + eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
160 | + } elseif (sizeof ($methodArgs) > 0) { |
|
161 | + self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
162 | + } else { |
|
163 | + self::$objects[$name]->$methodName (); |
|
164 | + } |
|
165 | + } catch (\Throwable $e) |
|
166 | 166 | { |
167 | - if (self::$throw_errors) |
|
168 | - throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
167 | + if (self::$throw_errors) { |
|
168 | + throw new \Exception ('Interpeter couldn\'t call method "'. $methodName .'" with arguments '. json_encode ($methodArgs) .' at line "'. $syntaxInfo['line'] .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
169 | + } |
|
169 | 170 | } |
171 | + } elseif (self::$throw_errors) { |
|
172 | + throw new \Exception ('Calling method to an non-object at line "'. $syntaxInfo['line'] .'"'); |
|
170 | 173 | } |
171 | - |
|
172 | - elseif (self::$throw_errors) |
|
173 | - throw new \Exception ('Calling method to an non-object at line "'. $syntaxInfo['line'] .'"'); |
|
174 | 174 | break; |
175 | 175 | |
176 | 176 | case VLF_RUNTIME_EXECUTABLE: |
@@ -178,16 +178,18 @@ discard block |
||
178 | 178 | break; |
179 | 179 | } |
180 | 180 | |
181 | - if (isset ($syntaxInfo['syntax_nodes']) && sizeof ($syntaxInfo['syntax_nodes']) > 0) |
|
182 | - self::$objects = self::run ($syntaxInfo['syntax_nodes'], null, $syntaxInfo); |
|
181 | + if (isset ($syntaxInfo['syntax_nodes']) && sizeof ($syntaxInfo['syntax_nodes']) > 0) { |
|
182 | + self::$objects = self::run ($syntaxInfo['syntax_nodes'], null, $syntaxInfo); |
|
183 | + } |
|
184 | + } else { |
|
185 | + throw new \Exception ('Catched unknown syntax node: "'. json_encode ($syntaxInfo) .'"'); |
|
183 | 186 | } |
184 | 187 | |
185 | - else throw new \Exception ('Catched unknown syntax node: "'. json_encode ($syntaxInfo) .'"'); |
|
186 | - |
|
187 | - if (is_dir ($resourcesDir)) |
|
188 | - foreach (glob ($resourcesDir .'/*.vrsf') as $id => $dir) |
|
188 | + if (is_dir ($resourcesDir)) { |
|
189 | + foreach (glob ($resourcesDir .'/*.vrsf') as $id => $dir) |
|
189 | 190 | { |
190 | 191 | $baseName = basenameNoExt ($dir); |
192 | + } |
|
191 | 193 | $info = explode ('.', $baseName); |
192 | 194 | |
193 | 195 | if (isset (self::$objects[$info[0]])) |
@@ -197,9 +199,9 @@ discard block |
||
197 | 199 | $collection = VoidEngine::getProperty (self::$objects[$info[0]]->selector, $info[1]); |
198 | 200 | |
199 | 201 | VoidEngine::callMethod ($collection, 'Add', [VoidEngine::importObject (base64_encode (file_get_contents ($dir))), 'object']); |
202 | + } else { |
|
203 | + VoidEngine::setProperty (self::$objects[$info[0]]->selector, $info[1], VoidEngine::importObject (base64_encode (file_get_contents ($dir)))); |
|
200 | 204 | } |
201 | - |
|
202 | - else VoidEngine::setProperty (self::$objects[$info[0]]->selector, $info[1], VoidEngine::importObject (base64_encode (file_get_contents ($dir)))); |
|
203 | 205 | } |
204 | 206 | } |
205 | 207 | |
@@ -239,8 +241,9 @@ discard block |
||
239 | 241 | |
240 | 242 | $nReplacement = []; |
241 | 243 | |
242 | - foreach ($replacement as $replaceTo => $nLn) |
|
243 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
244 | + foreach ($replacement as $replaceTo => $nLn) { |
|
245 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
246 | + } |
|
244 | 247 | |
245 | 248 | $replacement = $nReplacement; |
246 | 249 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -249,10 +252,11 @@ discard block |
||
249 | 252 | { |
250 | 253 | $replaced = false; |
251 | 254 | |
252 | - foreach ($replacement as $name => $replaceAt) |
|
253 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
255 | + foreach ($replacement as $name => $replaceAt) { |
|
256 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
254 | 257 | { |
255 | 258 | $newLine .= $replaceAt; |
259 | + } |
|
256 | 260 | |
257 | 261 | $i += $l - 1; |
258 | 262 | $replaced = true; |
@@ -260,8 +264,9 @@ discard block |
||
260 | 264 | break; |
261 | 265 | } |
262 | 266 | |
263 | - if (!$replaced) |
|
264 | - $newLine .= $line[$i]; |
|
267 | + if (!$replaced) { |
|
268 | + $newLine .= $line[$i]; |
|
269 | + } |
|
265 | 270 | } |
266 | 271 | |
267 | 272 | $line = $newLine; |