@@ -2,17 +2,17 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace VoidEngine; |
| 4 | 4 | |
| 5 | -$env = new WFClass ('System.Environment', 'mscorlib'); |
|
| 6 | -$params = $env->getCommandLineArgs ()->list; |
|
| 5 | +$env = new WFClass('System.Environment', 'mscorlib'); |
|
| 6 | +$params = $env->getCommandLineArgs()->list; |
|
| 7 | 7 | |
| 8 | -$converter = new WFClass ('System.Drawing.ColorTranslator'); |
|
| 8 | +$converter = new WFClass('System.Drawing.ColorTranslator'); |
|
| 9 | 9 | |
| 10 | 10 | $constants = [ |
| 11 | 11 | # Информация об окружении |
| 12 | 12 | |
| 13 | 13 | 'EXE_NAME' => $APPLICATION->executablePath, |
| 14 | - 'DOC_ROOT' => dirname ($APPLICATION->executablePath), |
|
| 15 | - 'IS_ADMIN' => is_writable (getenv ('SystemRoot')), |
|
| 14 | + 'DOC_ROOT' => dirname($APPLICATION->executablePath), |
|
| 15 | + 'IS_ADMIN' => is_writable(getenv('SystemRoot')), |
|
| 16 | 16 | 'START_PARAMS' => $params, |
| 17 | 17 | 'USERNAME' => $env->username, |
| 18 | 18 | |
@@ -332,17 +332,17 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | # Моя подборка цветов |
| 334 | 334 | |
| 335 | - 'clDark' => $converter->fromHtml ('#0D0F12'), |
|
| 336 | - 'clDark2' => $converter->fromHtml ('#121416'), |
|
| 337 | - 'clTurquoise' => $converter->fromHtml ('#00ADB5'), |
|
| 338 | - 'clLight' => $converter->fromHtml ('#EEEEEE') |
|
| 335 | + 'clDark' => $converter->fromHtml('#0D0F12'), |
|
| 336 | + 'clDark2' => $converter->fromHtml('#121416'), |
|
| 337 | + 'clTurquoise' => $converter->fromHtml('#00ADB5'), |
|
| 338 | + 'clLight' => $converter->fromHtml('#EEEEEE') |
|
| 339 | 339 | ]; |
| 340 | 340 | |
| 341 | 341 | foreach ($constants as $name => $value) |
| 342 | - define ($name, $value); |
|
| 342 | + define($name, $value); |
|
| 343 | 343 | |
| 344 | 344 | $argv = START_PARAMS; |
| 345 | -$argc = sizeof ($argv); |
|
| 345 | +$argc = sizeof($argv); |
|
| 346 | 346 | |
| 347 | -\VoidCore::removeObjects ($converter->selector); |
|
| 347 | +\VoidCore::removeObjects($converter->selector); |
|
| 348 | 348 | unset ($constants, $env, $params, $converter); |
@@ -2,50 +2,50 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace VoidEngine; |
| 4 | 4 | |
| 5 | -register_superglobals ('APPLICATION', 'SCREEN'); |
|
| 5 | +register_superglobals('APPLICATION', 'SCREEN'); |
|
| 6 | 6 | |
| 7 | 7 | $APPLICATION = new class |
| 8 | 8 | { |
| 9 | 9 | public WFClass $application; |
| 10 | 10 | public string $executablePath; |
| 11 | 11 | |
| 12 | - public function __construct () |
|
| 12 | + public function __construct() |
|
| 13 | 13 | { |
| 14 | - $this->application = new WFClass ('System.Windows.Forms.Application'); |
|
| 14 | + $this->application = new WFClass('System.Windows.Forms.Application'); |
|
| 15 | 15 | $this->executablePath = $this->application->executablePath; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function run ($form = null): void |
|
| 18 | + public function run($form = null): void |
|
| 19 | 19 | { |
| 20 | 20 | if ($form instanceof WFObject) |
| 21 | - $this->application->run ($form->selector); |
|
| 21 | + $this->application->run($form->selector); |
|
| 22 | 22 | |
| 23 | - elseif (is_int ($form) && \VoidCore::objectExists ($form)) |
|
| 24 | - $this->application->run ($form); |
|
| 23 | + elseif (is_int($form) && \VoidCore::objectExists($form)) |
|
| 24 | + $this->application->run($form); |
|
| 25 | 25 | |
| 26 | 26 | elseif ($form === null) |
| 27 | - $this->application->run (); |
|
| 27 | + $this->application->run(); |
|
| 28 | 28 | |
| 29 | - else throw new \Exception ('$form param must be instance of "VoidEngine\WFObject" ("VoidEngine\Form"), be null or object selector'); |
|
| 29 | + else throw new \Exception('$form param must be instance of "VoidEngine\WFObject" ("VoidEngine\Form"), be null or object selector'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function restart (): void |
|
| 32 | + public function restart(): void |
|
| 33 | 33 | { |
| 34 | - $this->application->restart (); |
|
| 35 | - $this->close (); |
|
| 34 | + $this->application->restart(); |
|
| 35 | + $this->close(); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function close (): void |
|
| 38 | + public function close(): void |
|
| 39 | 39 | { |
| 40 | - $this->application->exit (); |
|
| 40 | + $this->application->exit(); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function __call (string $name, array $args) |
|
| 43 | + public function __call(string $name, array $args) |
|
| 44 | 44 | { |
| 45 | - return $this->application->$name (...$args); |
|
| 45 | + return $this->application->$name(...$args); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function __get (string $name) |
|
| 48 | + public function __get(string $name) |
|
| 49 | 49 | { |
| 50 | 50 | return $this->application->$name; |
| 51 | 51 | } |
@@ -55,14 +55,14 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | public WFObject $screen; |
| 57 | 57 | |
| 58 | - public function __construct () |
|
| 58 | + public function __construct() |
|
| 59 | 59 | { |
| 60 | - $this->screen = new WFClass ('System.Windows.Forms.Screen'); |
|
| 60 | + $this->screen = new WFClass('System.Windows.Forms.Screen'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - public function __get ($name) |
|
| 63 | + public function __get($name) |
|
| 64 | 64 | { |
| 65 | - switch (strtolower ($name)) |
|
| 65 | + switch (strtolower($name)) |
|
| 66 | 66 | { |
| 67 | 67 | case 'width': |
| 68 | 68 | case 'w': |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function __debugInfo (): array |
|
| 83 | + public function __debugInfo(): array |
|
| 84 | 84 | { |
| 85 | 85 | return [ |
| 86 | 86 | $this->w, |
@@ -17,16 +17,15 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function run ($form = null): void |
| 19 | 19 | { |
| 20 | - if ($form instanceof WFObject) |
|
| 21 | - $this->application->run ($form->selector); |
|
| 22 | - |
|
| 23 | - elseif (is_int ($form) && \VoidCore::objectExists ($form)) |
|
| 24 | - $this->application->run ($form); |
|
| 25 | - |
|
| 26 | - elseif ($form === null) |
|
| 27 | - $this->application->run (); |
|
| 28 | - |
|
| 29 | - else throw new \Exception ('$form param must be instance of "VoidEngine\WFObject" ("VoidEngine\Form"), be null or object selector'); |
|
| 20 | + if ($form instanceof WFObject) { |
|
| 21 | + $this->application->run ($form->selector); |
|
| 22 | + } elseif (is_int ($form) && \VoidCore::objectExists ($form)) { |
|
| 23 | + $this->application->run ($form); |
|
| 24 | + } elseif ($form === null) { |
|
| 25 | + $this->application->run (); |
|
| 26 | + } else { |
|
| 27 | + throw new \Exception ('$form param must be instance of "VoidEngine\WFObject" ("VoidEngine\Form"), be null or object selector'); |
|
| 28 | + } |
|
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | public function restart (): void |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | const ENGINE_VERSION = '3.5.6 build-2019/09/22'; |
| 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; |
@@ -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 = \VoidCore::getProperty (self::$objects[$info[0]]->selector, $info[1]); |
|
| 197 | + $collection = \VoidCore::getProperty(self::$objects[$info[0]]->selector, $info[1]); |
|
| 198 | 198 | |
| 199 | - \VoidCore::callMethod ($collection, 'Add', [\VoidCore::importObject (base64_encode (file_get_contents ($dir))), 'object']); |
|
| 199 | + \VoidCore::callMethod($collection, 'Add', [\VoidCore::importObject(base64_encode(file_get_contents($dir))), 'object']); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - else \VoidCore::setProperty (self::$objects[$info[0]]->selector, $info[1], \VoidCore::importObject (base64_encode (file_get_contents ($dir)))); |
|
| 202 | + else \VoidCore::setProperty(self::$objects[$info[0]]->selector, $info[1], \VoidCore::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 = \VoidCore::getProperty (self::$objects[$info[0]]->selector, $info[1]); |
| 198 | 200 | |
| 199 | 201 | \VoidCore::callMethod ($collection, 'Add', [\VoidCore::importObject (base64_encode (file_get_contents ($dir))), 'object']); |
| 202 | + } else { |
|
| 203 | + \VoidCore::setProperty (self::$objects[$info[0]]->selector, $info[1], \VoidCore::importObject (base64_encode (file_get_contents ($dir)))); |
|
| 200 | 204 | } |
| 201 | - |
|
| 202 | - else \VoidCore::setProperty (self::$objects[$info[0]]->selector, $info[1], \VoidCore::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; |