@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | const ENGINE_VERSION = '4.0.0rc2'; |
35 | 35 | const ENGINE_DIR = __DIR__; |
36 | 36 | |
37 | -chdir (ENGINE_DIR); |
|
37 | +chdir(ENGINE_DIR); |
|
38 | 38 | |
39 | 39 | require 'common/Events.php'; |
40 | 40 | require 'common/EngineInterfaces.php'; |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | require 'common/Components.php'; |
44 | 44 | require 'common/Others.php'; |
45 | 45 | |
46 | -define ('VoidEngine\CORE_VERSION', $APPLICATION->productVersion); |
|
46 | +define('VoidEngine\CORE_VERSION', $APPLICATION->productVersion); |
|
47 | 47 | |
48 | 48 | require 'components/Component.php'; |
49 | 49 | require 'components/Control.php'; |
50 | 50 | |
51 | -foreach (glob ('components/*/*.php') as $name) |
|
51 | +foreach (glob('components/*/*.php') as $name) |
|
52 | 52 | require $name; |
53 | 53 | |
54 | -if (file_exists ('extensions')) |
|
55 | - foreach (scandir ('extensions') as $ext) |
|
56 | - if (file_exists ($ext = 'extensions/'. $ext .'/main.php')) |
|
54 | +if (file_exists('extensions')) |
|
55 | + foreach (scandir('extensions') as $ext) |
|
56 | + if (file_exists($ext = 'extensions/'.$ext.'/main.php')) |
|
57 | 57 | require $ext; |
@@ -9,25 +9,24 @@ |
||
9 | 9 | protected ?string $classname = 'System.Diagnostics.Process'; |
10 | 10 | protected ?string $assembly = 'System'; |
11 | 11 | |
12 | - public function __construct (int $pid = null) |
|
12 | + public function __construct(int $pid = null) |
|
13 | 13 | { |
14 | - $this->selector = VoidCore::getClass ($this->classname, $this->assembly); |
|
14 | + $this->selector = VoidCore::getClass($this->classname, $this->assembly); |
|
15 | 15 | |
16 | 16 | if ($pid !== null) |
17 | - $this->selector = $pid == getmypid () ? |
|
18 | - VoidCore::callMethod ($this->selector, 'GetCurrentProcess') : |
|
19 | - VoidCore::callMethod ($this->selector, 'GetProcessById', $pid); |
|
17 | + $this->selector = $pid == getmypid() ? |
|
18 | + VoidCore::callMethod($this->selector, 'GetCurrentProcess') : VoidCore::callMethod($this->selector, 'GetProcessById', $pid); |
|
20 | 19 | |
21 | - Components::add ($this); |
|
20 | + Components::add($this); |
|
22 | 21 | } |
23 | 22 | |
24 | - public static function getProcessById (int $pid) |
|
23 | + public static function getProcessById(int $pid) |
|
25 | 24 | { |
26 | - return new self ($pid); |
|
25 | + return new self($pid); |
|
27 | 26 | } |
28 | 27 | |
29 | - public static function getCurrentProcess () |
|
28 | + public static function getCurrentProcess() |
|
30 | 29 | { |
31 | - return new self (getmypid ()); |
|
30 | + return new self(getmypid()); |
|
32 | 31 | } |
33 | 32 | } |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return array - возвращает список созданных объектов |
22 | 22 | */ |
23 | - public static function run (AST $tree, Node $parent = null): array |
|
23 | + public static function run(AST $tree, Node $parent = null): array |
|
24 | 24 | { |
25 | - foreach ($tree->getNodes () as $id => $node) |
|
25 | + foreach ($tree->getNodes() as $id => $node) |
|
26 | 26 | { |
27 | 27 | switch ($node->type) |
28 | 28 | { |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | $args = $node->args['args']; |
40 | 40 | |
41 | 41 | foreach ($args as $arg_id => $arg) |
42 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
42 | + $args[$arg_id] = self::formatLine($arg, self::$objects); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | try |
46 | 46 | { |
47 | - self::$objects[$name] = eval ("namespace VoidEngine; return new $class (". implode (', ', $args) .");"); |
|
47 | + self::$objects[$name] = eval ("namespace VoidEngine; return new $class (".implode(', ', $args).");"); |
|
48 | 48 | |
49 | 49 | try |
50 | 50 | { |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | catch (\Throwable $e) |
58 | 58 | { |
59 | 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); |
|
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 | 61 | } |
62 | 62 | break; |
63 | 63 | |
@@ -70,35 +70,35 @@ discard block |
||
70 | 70 | $propertyValue = $node->args['value']; |
71 | 71 | $preset = ''; |
72 | 72 | |
73 | - if (preg_match ('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
73 | + if (preg_match('/function \((.*)\) use \((.*)\)/', $propertyValue)) |
|
74 | 74 | { |
75 | - $use = substr ($propertyValue, strpos ($propertyValue, 'use')); |
|
76 | - $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
|
77 | - $use = explode (' ', $use); |
|
75 | + $use = substr($propertyValue, strpos($propertyValue, 'use')); |
|
76 | + $use = $ouse = substr($use, ($pos = strpos($use, '(') + 1), strpos($use, ')') - $pos); |
|
77 | + $use = explode(' ', $use); |
|
78 | 78 | |
79 | 79 | foreach ($use as $id => $useParam) |
80 | 80 | if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
81 | 81 | { |
82 | 82 | $fname = $use[$id + 1]; |
83 | 83 | |
84 | - if (substr ($fname, strlen ($fname) - 1) == ',') |
|
85 | - $fname = substr ($fname, 0, -1); |
|
84 | + if (substr($fname, strlen($fname) - 1) == ',') |
|
85 | + $fname = substr($fname, 0, -1); |
|
86 | 86 | |
87 | 87 | $preset .= "$fname = $useParam; "; |
88 | 88 | |
89 | 89 | unset ($use[$id]); |
90 | 90 | } |
91 | 91 | |
92 | - $preset = self::formatLine ($preset, self::$objects); |
|
93 | - $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
|
92 | + $preset = self::formatLine($preset, self::$objects); |
|
93 | + $propertyValue = self::formatLine(str_replace($ouse, implode(' ', $use), $propertyValue), self::$objects); |
|
94 | 94 | } |
95 | 95 | |
96 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
96 | + else $propertyValue = self::formatLine($propertyValue, self::$objects); |
|
97 | 97 | |
98 | 98 | try |
99 | 99 | { |
100 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
101 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
100 | + if (strpos($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
101 | + eval ('namespace VoidEngine; '.$preset.' _c('.self::$objects[$name]->selector.')->'.$propertyName.' = '.$propertyValue.';'); |
|
102 | 102 | |
103 | 103 | else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
104 | 104 | } |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | catch (\Throwable $e) |
107 | 107 | { |
108 | 108 | if (self::$throw_errors) |
109 | - throw new \Exception ('Interpeter couldn\'t set property "'. $propertyName .'" with value "'. $propertyValue .'" at line "'. $node->line .'". Exception info:'. "\n\n". (string) $e, 0, $e); |
|
109 | + 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 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | 113 | elseif (self::$throw_errors) |
114 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
114 | + throw new \Exception('Setting property to an non-object at line "'.$node->line); |
|
115 | 115 | break; |
116 | 116 | |
117 | 117 | case METHOD_CALL: |
@@ -123,58 +123,58 @@ discard block |
||
123 | 123 | $methodArgs = $node->args['args']; |
124 | 124 | |
125 | 125 | foreach ($methodArgs as $arg_id => $arg) |
126 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
126 | + $methodArgs[$arg_id] = self::formatLine($arg, self::$objects); |
|
127 | 127 | |
128 | 128 | try |
129 | 129 | { |
130 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
131 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
130 | + if (strpos($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
131 | + eval ('namespace VoidEngine; _c('.self::$objects[$name]->selector.')->'.$methodName.' ('.implode(', ', $methodArgs).');'); |
|
132 | 132 | |
133 | - elseif (sizeof ($methodArgs) > 0) |
|
134 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
133 | + elseif (sizeof($methodArgs) > 0) |
|
134 | + self::$objects[$name]->$methodName(...eval ('namespace VoidEngine; return ['.implode(', ', $methodArgs).'];')); |
|
135 | 135 | |
136 | - else self::$objects[$name]->$methodName (); |
|
136 | + else self::$objects[$name]->$methodName(); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | catch (\Throwable $e) |
140 | 140 | { |
141 | 141 | if (self::$throw_errors) |
142 | - 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 | + 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); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | 146 | elseif (self::$throw_errors) |
147 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
147 | + throw new \Exception('Calling method to an non-object at line "'.$node->line.'"'); |
|
148 | 148 | break; |
149 | 149 | |
150 | 150 | case STYLES_IMPORTING: |
151 | 151 | foreach ($node->args['imports'] as $style) |
152 | 152 | { |
153 | - $path = eval ('namespace VoidEngine; return '. self::formatLine ($style, self::$objects) .';'); |
|
153 | + $path = eval ('namespace VoidEngine; return '.self::formatLine($style, self::$objects).';'); |
|
154 | 154 | |
155 | - if (!file_exists ($path)) |
|
156 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
155 | + if (!file_exists($path)) |
|
156 | + throw new \Exception('Trying to import nonexistent style at line "'.$node->line.'"'); |
|
157 | 157 | |
158 | - \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
|
158 | + \VLF\VST\Interpreter::run(\VLF\VST\Parser::parse(file_get_contents($path))); |
|
159 | 159 | } |
160 | 160 | break; |
161 | 161 | |
162 | 162 | case RUNTIME_EXECUTION: |
163 | - eval (self::formatLine ($node->args['code'], self::$objects)); |
|
163 | + eval (self::formatLine($node->args['code'], self::$objects)); |
|
164 | 164 | break; |
165 | 165 | } |
166 | 166 | |
167 | - $nodes = $node->getNodes (); |
|
167 | + $nodes = $node->getNodes(); |
|
168 | 168 | |
169 | 169 | if (isset ($node->args['styles'])) |
170 | 170 | foreach ($node->args['styles'] as $style) |
171 | 171 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
172 | - $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
172 | + $nodes = array_merge($nodes, \VLF\VST\Interpreter::$styles[$style]); |
|
173 | 173 | |
174 | - else throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
174 | + else throw new \Exception('Trying to set undefined style to object at line "'.$node->line.'"'); |
|
175 | 175 | |
176 | - self::$objects = self::run (new AST (array_map ( |
|
177 | - fn ($node) => $node->export (), $nodes)), $node); |
|
176 | + self::$objects = self::run(new AST(array_map( |
|
177 | + fn($node) => $node->export(), $nodes)), $node); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | return self::$objects; |
@@ -188,26 +188,25 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return string - возвращает форматированную строку |
190 | 190 | */ |
191 | - public static function formatLine (string $line, array $objects = []): string |
|
191 | + public static function formatLine(string $line, array $objects = []): string |
|
192 | 192 | { |
193 | - if (sizeof ($objects) > 0) |
|
193 | + if (sizeof($objects) > 0) |
|
194 | 194 | { |
195 | - $len = strlen ($line); |
|
195 | + $len = strlen($line); |
|
196 | 196 | $newLine = ''; |
197 | 197 | |
198 | - $replacement = array_map (function ($object) |
|
198 | + $replacement = array_map(function($object) |
|
199 | 199 | { |
200 | - return \VoidEngine\Components::exists ($object->selector) !== false ? |
|
201 | - '\VoidEngine\_c('. $object->selector .')' : |
|
202 | - 'unserialize (\''. serialize ($object) .'\')'; |
|
200 | + return \VoidEngine\Components::exists($object->selector) !== false ? |
|
201 | + '\VoidEngine\_c('.$object->selector.')' : 'unserialize (\''.serialize($object).'\')'; |
|
203 | 202 | }, $objects); |
204 | 203 | |
205 | - $replacement = array_map (function ($name) |
|
204 | + $replacement = array_map(function($name) |
|
206 | 205 | { |
207 | - return strlen ($name = trim ($name)) + substr_count ($name, '_'); |
|
208 | - }, $omap = array_flip ($replacement)); |
|
206 | + return strlen($name = trim($name)) + substr_count($name, '_'); |
|
207 | + }, $omap = array_flip($replacement)); |
|
209 | 208 | |
210 | - arsort ($replacement); |
|
209 | + arsort($replacement); |
|
211 | 210 | |
212 | 211 | $nReplacement = []; |
213 | 212 | |
@@ -215,14 +214,14 @@ discard block |
||
215 | 214 | $nReplacement[$omap[$replaceTo]] = $replaceTo; |
216 | 215 | |
217 | 216 | $replacement = $nReplacement; |
218 | - $blacklist = array_flip (['\'', '"', '$']); |
|
217 | + $blacklist = array_flip(['\'', '"', '$']); |
|
219 | 218 | |
220 | 219 | for ($i = 0; $i < $len; ++$i) |
221 | 220 | { |
222 | 221 | $replaced = false; |
223 | 222 | |
224 | 223 | foreach ($replacement as $name => $replaceAt) |
225 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
224 | + if (substr($line, $i, ($l = strlen($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
226 | 225 | { |
227 | 226 | $newLine .= $replaceAt; |
228 | 227 |
@@ -26,30 +26,30 @@ |
||
26 | 26 | * |
27 | 27 | * @return array - возвращает список созданных объектов |
28 | 28 | */ |
29 | - public static function run (AST $tree, Node $parent = null): array |
|
29 | + public static function run(AST $tree, Node $parent = null): array |
|
30 | 30 | { |
31 | - foreach ($tree->getNodes () as $id => $node) |
|
31 | + foreach ($tree->getNodes() as $id => $node) |
|
32 | 32 | { |
33 | 33 | if ($node->type == \VLF\STYLE_DEFINITION) |
34 | 34 | { |
35 | 35 | $name = $node->args['name']; |
36 | - $nodes = $node->getNodes (); |
|
36 | + $nodes = $node->getNodes(); |
|
37 | 37 | |
38 | 38 | if ($node->args['parents'] !== null) |
39 | 39 | foreach ($node->args['parents'] as $parent) |
40 | 40 | { |
41 | 41 | if (!isset (self::$styles[$parent]) && self::$throw_errors) |
42 | - throw new \Exception ('Style "'. $parent .'" not founded'); |
|
42 | + throw new \Exception('Style "'.$parent.'" not founded'); |
|
43 | 43 | |
44 | - $nodes = array_merge (self::$styles[$parent], $nodes); |
|
44 | + $nodes = array_merge(self::$styles[$parent], $nodes); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | self::$styles[$name] = isset (self::$objects[$name]) ? |
48 | 48 | array_merge (self::$styles[$name], $nodes) : $nodes; |
49 | 49 | } |
50 | 50 | |
51 | - self::$styles = self::run (new AST (array_map ( |
|
52 | - fn ($node) => $node->export (), $node->getNodes ())), $node); |
|
51 | + self::$styles = self::run(new AST(array_map( |
|
52 | + fn($node) => $node->export(), $node->getNodes())), $node); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return self::$styles; |