@@ -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; |
@@ -6,28 +6,28 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Process extends Component |
| 8 | 8 | { |
| 9 | - protected ?string $classname = 'System.Diagnostics.Process'; |
|
| 10 | - protected ?string $assembly = 'System'; |
|
| 9 | + protected ?string $classname = 'System.Diagnostics.Process'; |
|
| 10 | + protected ?string $assembly = 'System'; |
|
| 11 | 11 | |
| 12 | - public function __construct (int $pid = null) |
|
| 13 | - { |
|
| 12 | + public function __construct (int $pid = null) |
|
| 13 | + { |
|
| 14 | 14 | $this->selector = VoidCore::getClass ($this->classname, $this->assembly); |
| 15 | 15 | |
| 16 | - if ($pid !== null) |
|
| 16 | + if ($pid !== null) |
|
| 17 | 17 | $this->selector = $pid == getmypid () ? |
| 18 | 18 | VoidCore::callMethod ($this->selector, 'GetCurrentProcess') : |
| 19 | 19 | VoidCore::callMethod ($this->selector, 'GetProcessById', $pid); |
| 20 | 20 | |
| 21 | - Components::add ($this); |
|
| 22 | - } |
|
| 21 | + Components::add ($this); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public static function getProcessById (int $pid) |
|
| 25 | - { |
|
| 26 | - return new self ($pid); |
|
| 27 | - } |
|
| 24 | + public static function getProcessById (int $pid) |
|
| 25 | + { |
|
| 26 | + return new self ($pid); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public static function getCurrentProcess () |
|
| 30 | - { |
|
| 31 | - return new self (getmypid ()); |
|
| 32 | - } |
|
| 29 | + public static function getCurrentProcess () |
|
| 30 | + { |
|
| 31 | + return new self (getmypid ()); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -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 | } |
@@ -13,10 +13,11 @@ |
||
| 13 | 13 | { |
| 14 | 14 | $this->selector = VoidCore::getClass ($this->classname, $this->assembly); |
| 15 | 15 | |
| 16 | - if ($pid !== null) |
|
| 17 | - $this->selector = $pid == getmypid () ? |
|
| 16 | + if ($pid !== null) { |
|
| 17 | + $this->selector = $pid == getmypid () ? |
|
| 18 | 18 | VoidCore::callMethod ($this->selector, 'GetCurrentProcess') : |
| 19 | 19 | VoidCore::callMethod ($this->selector, 'GetProcessById', $pid); |
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | Components::add ($this); |
| 22 | 23 | } |
@@ -97,7 +97,7 @@ |
||
| 97 | 97 | |
| 98 | 98 | try |
| 99 | 99 | { |
| 100 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
| 100 | + if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
| 101 | 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;"); |
@@ -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 | |
@@ -31,15 +31,17 @@ discard block |
||
| 31 | 31 | $name = $node->args['name']; |
| 32 | 32 | $args = []; |
| 33 | 33 | |
| 34 | - if (isset (self::$objects[$name])) |
|
| 35 | - break; |
|
| 34 | + if (isset (self::$objects[$name])) { |
|
| 35 | + break; |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | if (isset ($node->args['args'])) |
| 38 | 39 | { |
| 39 | 40 | $args = $node->args['args']; |
| 40 | 41 | |
| 41 | - foreach ($args as $arg_id => $arg) |
|
| 42 | - $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 42 | + foreach ($args as $arg_id => $arg) { |
|
| 43 | + $args[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | try |
@@ -49,15 +51,12 @@ discard block |
||
| 49 | 51 | try |
| 50 | 52 | { |
| 51 | 53 | self::$objects[$name]->name = $name; |
| 52 | - } |
|
| 53 | - |
|
| 54 | - catch (\Throwable $e) {} |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - catch (\Throwable $e) |
|
| 54 | + } catch (\Throwable $e) {} |
|
| 55 | + } catch (\Throwable $e) |
|
| 58 | 56 | { |
| 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); |
|
| 57 | + if (self::$throw_errors) { |
|
| 58 | + 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 | + } |
|
| 61 | 60 | } |
| 62 | 61 | break; |
| 63 | 62 | |
@@ -76,13 +75,15 @@ discard block |
||
| 76 | 75 | $use = $ouse = substr ($use, ($pos = strpos ($use, '(') + 1), strpos ($use, ')') - $pos); |
| 77 | 76 | $use = explode (' ', $use); |
| 78 | 77 | |
| 79 | - foreach ($use as $id => $useParam) |
|
| 80 | - if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 78 | + foreach ($use as $id => $useParam) { |
|
| 79 | + if (isset (self::$objects[$useParam]) && $use[$id + 1][0] == '$') |
|
| 81 | 80 | { |
| 82 | 81 | $fname = $use[$id + 1]; |
| 82 | + } |
|
| 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 | 88 | $preset .= "$fname = $useParam; "; |
| 88 | 89 | |
@@ -91,27 +92,26 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | $preset = self::formatLine ($preset, self::$objects); |
| 93 | 94 | $propertyValue = self::formatLine (str_replace ($ouse, implode (' ', $use), $propertyValue), self::$objects); |
| 95 | + } else { |
|
| 96 | + $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 94 | 97 | } |
| 95 | 98 | |
| 96 | - else $propertyValue = self::formatLine ($propertyValue, self::$objects); |
|
| 97 | - |
|
| 98 | 99 | try |
| 99 | 100 | { |
| 100 | - if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) |
|
| 101 | - eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
| 102 | - |
|
| 103 | - else self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - catch (\Throwable $e) |
|
| 101 | + if (strpos ($propertyName, '->') !== false && self::$allow_multimethods_calls) { |
|
| 102 | + eval ('namespace VoidEngine; '. $preset .' _c('. self::$objects[$name]->selector .')->'. $propertyName .' = '. $propertyValue .';'); |
|
| 103 | + } else { |
|
| 104 | + self::$objects[$name]->$propertyName = eval ("namespace VoidEngine; $preset return $propertyValue;"); |
|
| 105 | + } |
|
| 106 | + } catch (\Throwable $e) |
|
| 107 | 107 | { |
| 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); |
|
| 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); |
|
| 110 | + } |
|
| 110 | 111 | } |
| 112 | + } elseif (self::$throw_errors) { |
|
| 113 | + throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 111 | 114 | } |
| 112 | - |
|
| 113 | - elseif (self::$throw_errors) |
|
| 114 | - throw new \Exception ('Setting property to an non-object at line "'. $node->line); |
|
| 115 | 115 | break; |
| 116 | 116 | |
| 117 | 117 | case METHOD_CALL: |
@@ -122,29 +122,28 @@ discard block |
||
| 122 | 122 | $methodName = $node->args['name']; |
| 123 | 123 | $methodArgs = $node->args['args']; |
| 124 | 124 | |
| 125 | - foreach ($methodArgs as $arg_id => $arg) |
|
| 126 | - $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 125 | + foreach ($methodArgs as $arg_id => $arg) { |
|
| 126 | + $methodArgs[$arg_id] = self::formatLine ($arg, self::$objects); |
|
| 127 | + } |
|
| 127 | 128 | |
| 128 | 129 | try |
| 129 | 130 | { |
| 130 | - if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) |
|
| 131 | - eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 132 | - |
|
| 133 | - elseif (sizeof ($methodArgs) > 0) |
|
| 134 | - self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 135 | - |
|
| 136 | - else self::$objects[$name]->$methodName (); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - catch (\Throwable $e) |
|
| 131 | + if (strpos ($methodName, '->') !== false && self::$allow_multimethods_calls) { |
|
| 132 | + eval ('namespace VoidEngine; _c('. self::$objects[$name]->selector .')->'. $methodName .' ('. implode (', ', $methodArgs) .');'); |
|
| 133 | + } elseif (sizeof ($methodArgs) > 0) { |
|
| 134 | + self::$objects[$name]->$methodName (...eval ('namespace VoidEngine; return ['. implode (', ', $methodArgs) .'];')); |
|
| 135 | + } else { |
|
| 136 | + self::$objects[$name]->$methodName (); |
|
| 137 | + } |
|
| 138 | + } catch (\Throwable $e) |
|
| 140 | 139 | { |
| 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); |
|
| 140 | + if (self::$throw_errors) { |
|
| 141 | + 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 | + } |
|
| 143 | 143 | } |
| 144 | + } elseif (self::$throw_errors) { |
|
| 145 | + throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 144 | 146 | } |
| 145 | - |
|
| 146 | - elseif (self::$throw_errors) |
|
| 147 | - throw new \Exception ('Calling method to an non-object at line "'. $node->line .'"'); |
|
| 148 | 147 | break; |
| 149 | 148 | |
| 150 | 149 | case STYLES_IMPORTING: |
@@ -152,8 +151,9 @@ discard block |
||
| 152 | 151 | { |
| 153 | 152 | $path = eval ('namespace VoidEngine; return '. self::formatLine ($style, self::$objects) .';'); |
| 154 | 153 | |
| 155 | - if (!file_exists ($path)) |
|
| 156 | - throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 154 | + if (!file_exists ($path)) { |
|
| 155 | + throw new \Exception ('Trying to import nonexistent style at line "'. $node->line .'"'); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | \VLF\VST\Interpreter::run (\VLF\VST\Parser::parse (file_get_contents ($path))); |
| 159 | 159 | } |
@@ -166,12 +166,13 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $nodes = $node->getNodes (); |
| 168 | 168 | |
| 169 | - if (isset ($node->args['styles'])) |
|
| 170 | - foreach ($node->args['styles'] as $style) |
|
| 169 | + if (isset ($node->args['styles'])) { |
|
| 170 | + foreach ($node->args['styles'] as $style) |
|
| 171 | 171 | if (isset (\VLF\VST\Interpreter::$styles[$style])) |
| 172 | 172 | $nodes = array_merge ($nodes, \VLF\VST\Interpreter::$styles[$style]); |
| 173 | - |
|
| 174 | - else throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
| 173 | + } else { |
|
| 174 | + throw new \Exception ('Trying to set undefined style to object at line "'. $node->line .'"'); |
|
| 175 | + } |
|
| 175 | 176 | |
| 176 | 177 | self::$objects = self::run (new AST (array_map ( |
| 177 | 178 | fn ($node) => $node->export (), $nodes)), $node); |
@@ -211,8 +212,9 @@ discard block |
||
| 211 | 212 | |
| 212 | 213 | $nReplacement = []; |
| 213 | 214 | |
| 214 | - foreach ($replacement as $replaceTo => $nLn) |
|
| 215 | - $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 215 | + foreach ($replacement as $replaceTo => $nLn) { |
|
| 216 | + $nReplacement[$omap[$replaceTo]] = $replaceTo; |
|
| 217 | + } |
|
| 216 | 218 | |
| 217 | 219 | $replacement = $nReplacement; |
| 218 | 220 | $blacklist = array_flip (['\'', '"', '$']); |
@@ -221,10 +223,11 @@ discard block |
||
| 221 | 223 | { |
| 222 | 224 | $replaced = false; |
| 223 | 225 | |
| 224 | - foreach ($replacement as $name => $replaceAt) |
|
| 225 | - if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 226 | + foreach ($replacement as $name => $replaceAt) { |
|
| 227 | + if (substr ($line, $i, ($l = strlen ($name))) == $name && !isset ($blacklist[$line[$i - 1]])) |
|
| 226 | 228 | { |
| 227 | 229 | $newLine .= $replaceAt; |
| 230 | + } |
|
| 228 | 231 | |
| 229 | 232 | $i += $l - 1; |
| 230 | 233 | $replaced = true; |
@@ -232,8 +235,9 @@ discard block |
||
| 232 | 235 | break; |
| 233 | 236 | } |
| 234 | 237 | |
| 235 | - if (!$replaced) |
|
| 236 | - $newLine .= $line[$i]; |
|
| 238 | + if (!$replaced) { |
|
| 239 | + $newLine .= $line[$i]; |
|
| 240 | + } |
|
| 237 | 241 | } |
| 238 | 242 | |
| 239 | 243 | $line = $newLine; |
@@ -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; |
@@ -35,11 +35,12 @@ |
||
| 35 | 35 | $name = $node->args['name']; |
| 36 | 36 | $nodes = $node->getNodes (); |
| 37 | 37 | |
| 38 | - if ($node->args['parents'] !== null) |
|
| 39 | - foreach ($node->args['parents'] as $parent) |
|
| 38 | + if ($node->args['parents'] !== null) { |
|
| 39 | + foreach ($node->args['parents'] as $parent) |
|
| 40 | 40 | { |
| 41 | 41 | if (!isset (self::$styles[$parent]) && self::$throw_errors) |
| 42 | 42 | throw new \Exception ('Style "'. $parent .'" not founded'); |
| 43 | + } |
|
| 43 | 44 | |
| 44 | 45 | $nodes = array_merge (self::$styles[$parent], $nodes); |
| 45 | 46 | } |