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