@@ -13,10 +13,10 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | if (!isset ($argv)) |
| 15 | 15 | { |
| 16 | - $params = json_decode (file_get_contents (__DIR__ .'/params.json'), true); |
|
| 17 | - $oargv = [__FILE__]; |
|
| 16 | + $params = json_decode (file_get_contents (__DIR__ .'/params.json'), true); |
|
| 17 | + $oargv = [__FILE__]; |
|
| 18 | 18 | |
| 19 | - unlink (__DIR__ .'/params.json'); |
|
| 19 | + unlink (__DIR__ .'/params.json'); |
|
| 20 | 20 | |
| 21 | 21 | foreach ($params as $name => $param) |
| 22 | 22 | { |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | if (!defined ('VoidBuilder\CORE_DIR')) |
| 38 | 38 | define ('VoidBuilder\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
| 39 | 39 | |
| 40 | - define ('VoidEngine\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 40 | + define ('VoidEngine\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 41 | 41 | |
| 42 | 42 | require $params['--engine-dir'] .'/VoidEngine.php'; |
| 43 | 43 | |
| 44 | - $argv = $oargv; |
|
| 44 | + $argv = $oargv; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | try |
@@ -13,103 +13,103 @@ |
||
| 13 | 13 | |
| 14 | 14 | if (!isset ($argv)) |
| 15 | 15 | { |
| 16 | - $params = json_decode (file_get_contents (__DIR__ .'/params.json'), true); |
|
| 16 | + $params = json_decode(file_get_contents(__DIR__.'/params.json'), true); |
|
| 17 | 17 | $oargv = [__FILE__]; |
| 18 | 18 | |
| 19 | - unlink (__DIR__ .'/params.json'); |
|
| 19 | + unlink(__DIR__.'/params.json'); |
|
| 20 | 20 | |
| 21 | 21 | foreach ($params as $name => $param) |
| 22 | 22 | { |
| 23 | - if (!is_array ($param)) |
|
| 23 | + if (!is_array($param)) |
|
| 24 | 24 | $param = [$param]; |
| 25 | 25 | |
| 26 | 26 | foreach ($param as $arg) |
| 27 | - if (strlen ($arg) > 0) |
|
| 27 | + if (strlen($arg) > 0) |
|
| 28 | 28 | { |
| 29 | 29 | $oargv[] = $name; |
| 30 | 30 | $oargv[] = $arg; |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if (!defined ('VoidBuilder\ENGINE_DIR')) |
|
| 35 | - define ('VoidBuilder\ENGINE_DIR', $params['--engine-dir']); |
|
| 34 | + if (!defined('VoidBuilder\ENGINE_DIR')) |
|
| 35 | + define('VoidBuilder\ENGINE_DIR', $params['--engine-dir']); |
|
| 36 | 36 | |
| 37 | - if (!defined ('VoidBuilder\CORE_DIR')) |
|
| 38 | - define ('VoidBuilder\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 37 | + if (!defined('VoidBuilder\CORE_DIR')) |
|
| 38 | + define('VoidBuilder\CORE_DIR', dirname(ENGINE_DIR).'/core'); |
|
| 39 | 39 | |
| 40 | - define ('VoidEngine\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 40 | + define('VoidEngine\CORE_DIR', dirname(ENGINE_DIR).'/core'); |
|
| 41 | 41 | |
| 42 | - require $params['--engine-dir'] .'/VoidEngine.php'; |
|
| 42 | + require $params['--engine-dir'].'/VoidEngine.php'; |
|
| 43 | 43 | |
| 44 | 44 | $argv = $oargv; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | try |
| 48 | 48 | { |
| 49 | - (new Manager ([], (new DefaultCommand (function ($args, $params) |
|
| 49 | + (new Manager([], (new DefaultCommand(function($args, $params) |
|
| 50 | 50 | { |
| 51 | 51 | foreach (['--app-dir', '--output-dir', '--icon-path'] as $param) |
| 52 | - if (is_array ($params[$param])) |
|
| 53 | - $params[$param] = end ($params[$param]); |
|
| 52 | + if (is_array($params[$param])) |
|
| 53 | + $params[$param] = end($params[$param]); |
|
| 54 | 54 | |
| 55 | - if (!file_exists (dirname ($params['--app-dir']) .'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe')) |
|
| 55 | + if (!file_exists(dirname($params['--app-dir']).'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe')) |
|
| 56 | 56 | die ("\n Incorrect VoidFramework app path\n"); |
| 57 | 57 | |
| 58 | - if (class_exists ('VoidEngine\WFObject')) |
|
| 58 | + if (class_exists('VoidEngine\WFObject')) |
|
| 59 | 59 | { |
| 60 | - $errors = (new Builder ($params['--app-dir'])) |
|
| 61 | - ->build ($params['--output-dir'], $params['--icon-path'], !$params['--no-compress']); |
|
| 60 | + $errors = (new Builder($params['--app-dir'])) |
|
| 61 | + ->build($params['--output-dir'], $params['--icon-path'], !$params['--no-compress']); |
|
| 62 | 62 | |
| 63 | - if (sizeof ($errors) > 0) |
|
| 64 | - print_r ($errors); |
|
| 63 | + if (sizeof($errors) > 0) |
|
| 64 | + print_r($errors); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | else |
| 68 | 68 | { |
| 69 | 69 | echo PHP_EOL; |
| 70 | - echo ' Building ['. dirname (str_replace (dirname ($params['--app-dir'], 2) .'\\', '', $params['--app-dir'])) .']...'. PHP_EOL . PHP_EOL; |
|
| 70 | + echo ' Building ['.dirname(str_replace(dirname($params['--app-dir'], 2).'\\', '', $params['--app-dir'])).']...'.PHP_EOL.PHP_EOL; |
|
| 71 | 71 | |
| 72 | - $begin = microtime (true); |
|
| 72 | + $begin = microtime(true); |
|
| 73 | 73 | |
| 74 | - $params['--engine-dir'] = dirname ($params['--app-dir']) .'/qero-packages/winforms-php/VoidFramework/engine'; |
|
| 75 | - file_put_contents ('params.json', json_encode ($params, JSON_PRETTY_PRINT)); |
|
| 74 | + $params['--engine-dir'] = dirname($params['--app-dir']).'/qero-packages/winforms-php/VoidFramework/engine'; |
|
| 75 | + file_put_contents('params.json', json_encode($params, JSON_PRETTY_PRINT)); |
|
| 76 | 76 | |
| 77 | - shell_exec ('"'. dirname ($params['--app-dir']) .'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe" "'. __FILE__ .'"'); |
|
| 77 | + shell_exec('"'.dirname($params['--app-dir']).'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe" "'.__FILE__.'"'); |
|
| 78 | 78 | |
| 79 | - echo ' Building completed after '. round (microtime (true) - $begin, 6) .' seconds'. PHP_EOL; |
|
| 80 | - echo ' Saved at '. $params['--output-dir'] .'/build'. PHP_EOL . PHP_EOL; |
|
| 79 | + echo ' Building completed after '.round(microtime(true) - $begin, 6).' seconds'.PHP_EOL; |
|
| 80 | + echo ' Saved at '.$params['--output-dir'].'/build'.PHP_EOL.PHP_EOL; |
|
| 81 | 81 | |
| 82 | 82 | if (isset ($params['--join'])) |
| 83 | 83 | { |
| 84 | - if (!is_array ($params['--join'])) |
|
| 84 | + if (!is_array($params['--join'])) |
|
| 85 | 85 | $params['--join'] = [$params['--join']]; |
| 86 | 86 | |
| 87 | - if (($size = sizeof ($params['--join'])) > 0) |
|
| 87 | + if (($size = sizeof($params['--join'])) > 0) |
|
| 88 | 88 | { |
| 89 | - echo ' Union '. $size .' files...'. PHP_EOL; |
|
| 89 | + echo ' Union '.$size.' files...'.PHP_EOL; |
|
| 90 | 90 | |
| 91 | - $begin = microtime (true); |
|
| 92 | - $joiner = new Joiner ($params['--output-dir'] .'/build/app.exe', $params['--output-dir'] .'/app.exe'); |
|
| 91 | + $begin = microtime(true); |
|
| 92 | + $joiner = new Joiner($params['--output-dir'].'/build/app.exe', $params['--output-dir'].'/app.exe'); |
|
| 93 | 93 | |
| 94 | 94 | foreach ($params['--join'] as $file) |
| 95 | - $joiner->add (file_exists ($file) ? $file : $params['--output-dir'] .'/build/'. $file); |
|
| 95 | + $joiner->add(file_exists($file) ? $file : $params['--output-dir'].'/build/'.$file); |
|
| 96 | 96 | |
| 97 | - echo str_replace ("\n", "\n ", $joiner->join ()) . PHP_EOL; |
|
| 98 | - echo ' Union completed after '. round (microtime (true) - $begin, 6) .' seconds'. PHP_EOL; |
|
| 99 | - echo ' Saved at '. $params['--output-dir'] . PHP_EOL; |
|
| 97 | + echo str_replace("\n", "\n ", $joiner->join()).PHP_EOL; |
|
| 98 | + echo ' Union completed after '.round(microtime(true) - $begin, 6).' seconds'.PHP_EOL; |
|
| 99 | + echo ' Saved at '.$params['--output-dir'].PHP_EOL; |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - }))->addParams ([ |
|
| 104 | - (new Param ('--app-dir', null, true))->addAliase ('-d'), |
|
| 105 | - (new Param ('--output-dir', __DIR__ .'/build'))->addAliase ('-o'), |
|
| 106 | - (new Param ('--icon-path', __DIR__ .'/system/Icon.ico'))->addAliase ('-i'), |
|
| 107 | - (new Param ('--join'))->addAliase ('-j'), |
|
| 108 | - (new Flag ('--no-compress'))->addAliase ('-nc') |
|
| 109 | - ])))->execute ($argv); |
|
| 103 | + }))->addParams([ |
|
| 104 | + (new Param('--app-dir', null, true))->addAliase('-d'), |
|
| 105 | + (new Param('--output-dir', __DIR__.'/build'))->addAliase('-o'), |
|
| 106 | + (new Param('--icon-path', __DIR__.'/system/Icon.ico'))->addAliase('-i'), |
|
| 107 | + (new Param('--join'))->addAliase('-j'), |
|
| 108 | + (new Flag('--no-compress'))->addAliase('-nc') |
|
| 109 | + ])))->execute($argv); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | catch (\Exception $e) |
| 113 | 113 | { |
| 114 | - die ("\n ". $e->getMessage () ."\n"); |
|
| 114 | + die ("\n ".$e->getMessage()."\n"); |
|
| 115 | 115 | } |
@@ -20,22 +20,26 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | foreach ($params as $name => $param) |
| 22 | 22 | { |
| 23 | - if (!is_array ($param)) |
|
| 24 | - $param = [$param]; |
|
| 23 | + if (!is_array ($param)) { |
|
| 24 | + $param = [$param]; |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | - foreach ($param as $arg) |
|
| 27 | - if (strlen ($arg) > 0) |
|
| 27 | + foreach ($param as $arg) { |
|
| 28 | + if (strlen ($arg) > 0) |
|
| 28 | 29 | { |
| 29 | 30 | $oargv[] = $name; |
| 31 | + } |
|
| 30 | 32 | $oargv[] = $arg; |
| 31 | 33 | } |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | - if (!defined ('VoidBuilder\ENGINE_DIR')) |
|
| 35 | - define ('VoidBuilder\ENGINE_DIR', $params['--engine-dir']); |
|
| 36 | + if (!defined ('VoidBuilder\ENGINE_DIR')) { |
|
| 37 | + define ('VoidBuilder\ENGINE_DIR', $params['--engine-dir']); |
|
| 38 | + } |
|
| 36 | 39 | |
| 37 | - if (!defined ('VoidBuilder\CORE_DIR')) |
|
| 38 | - define ('VoidBuilder\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 40 | + if (!defined ('VoidBuilder\CORE_DIR')) { |
|
| 41 | + define ('VoidBuilder\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
|
| 42 | + } |
|
| 39 | 43 | |
| 40 | 44 | define ('VoidEngine\CORE_DIR', dirname (ENGINE_DIR) .'/core'); |
| 41 | 45 | |
@@ -48,23 +52,24 @@ discard block |
||
| 48 | 52 | { |
| 49 | 53 | (new Manager ([], (new DefaultCommand (function ($args, $params) |
| 50 | 54 | { |
| 51 | - foreach (['--app-dir', '--output-dir', '--icon-path'] as $param) |
|
| 52 | - if (is_array ($params[$param])) |
|
| 55 | + foreach (['--app-dir', '--output-dir', '--icon-path'] as $param) { |
|
| 56 | + if (is_array ($params[$param])) |
|
| 53 | 57 | $params[$param] = end ($params[$param]); |
| 58 | + } |
|
| 54 | 59 | |
| 55 | - if (!file_exists (dirname ($params['--app-dir']) .'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe')) |
|
| 56 | - die ("\n Incorrect VoidFramework app path\n"); |
|
| 60 | + if (!file_exists (dirname ($params['--app-dir']) .'/qero-packages/winforms-php/VoidFramework/core/VoidCore.exe')) { |
|
| 61 | + die ("\n Incorrect VoidFramework app path\n"); |
|
| 62 | + } |
|
| 57 | 63 | |
| 58 | 64 | if (class_exists ('VoidEngine\WFObject')) |
| 59 | 65 | { |
| 60 | 66 | $errors = (new Builder ($params['--app-dir'])) |
| 61 | 67 | ->build ($params['--output-dir'], $params['--icon-path'], !$params['--no-compress']); |
| 62 | 68 | |
| 63 | - if (sizeof ($errors) > 0) |
|
| 64 | - print_r ($errors); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - else |
|
| 69 | + if (sizeof ($errors) > 0) { |
|
| 70 | + print_r ($errors); |
|
| 71 | + } |
|
| 72 | + } else |
|
| 68 | 73 | { |
| 69 | 74 | echo PHP_EOL; |
| 70 | 75 | echo ' Building ['. dirname (str_replace (dirname ($params['--app-dir'], 2) .'\\', '', $params['--app-dir'])) .']...'. PHP_EOL . PHP_EOL; |
@@ -81,8 +86,9 @@ discard block |
||
| 81 | 86 | |
| 82 | 87 | if (isset ($params['--join'])) |
| 83 | 88 | { |
| 84 | - if (!is_array ($params['--join'])) |
|
| 85 | - $params['--join'] = [$params['--join']]; |
|
| 89 | + if (!is_array ($params['--join'])) { |
|
| 90 | + $params['--join'] = [$params['--join']]; |
|
| 91 | + } |
|
| 86 | 92 | |
| 87 | 93 | if (($size = sizeof ($params['--join'])) > 0) |
| 88 | 94 | { |
@@ -91,8 +97,9 @@ discard block |
||
| 91 | 97 | $begin = microtime (true); |
| 92 | 98 | $joiner = new Joiner ($params['--output-dir'] .'/build/app.exe', $params['--output-dir'] .'/app.exe'); |
| 93 | 99 | |
| 94 | - foreach ($params['--join'] as $file) |
|
| 95 | - $joiner->add (file_exists ($file) ? $file : $params['--output-dir'] .'/build/'. $file); |
|
| 100 | + foreach ($params['--join'] as $file) { |
|
| 101 | + $joiner->add (file_exists ($file) ? $file : $params['--output-dir'] .'/build/'. $file); |
|
| 102 | + } |
|
| 96 | 103 | |
| 97 | 104 | echo str_replace ("\n", "\n ", $joiner->join ()) . PHP_EOL; |
| 98 | 105 | echo ' Union completed after '. round (microtime (true) - $begin, 6) .' seconds'. PHP_EOL; |
@@ -107,9 +114,7 @@ discard block |
||
| 107 | 114 | (new Param ('--join'))->addAliase ('-j'), |
| 108 | 115 | (new Flag ('--no-compress'))->addAliase ('-nc') |
| 109 | 116 | ])))->execute ($argv); |
| 110 | -} |
|
| 111 | - |
|
| 112 | -catch (\Exception $e) |
|
| 117 | +} catch (\Exception $e) |
|
| 113 | 118 | { |
| 114 | 119 | die ("\n ". $e->getMessage () ."\n"); |
| 115 | 120 | } |
@@ -2,65 +2,65 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace VoidBuilder; |
| 4 | 4 | |
| 5 | -if (!defined ('VoidBuilder\ENGINE_DIR') && defined ('VoidEngine\ENGINE_DIR')) |
|
| 6 | - define ('VoidBuilder\ENGINE_DIR', \VoidEngine\ENGINE_DIR); |
|
| 5 | +if (!defined('VoidBuilder\ENGINE_DIR') && defined('VoidEngine\ENGINE_DIR')) |
|
| 6 | + define('VoidBuilder\ENGINE_DIR', \VoidEngine\ENGINE_DIR); |
|
| 7 | 7 | |
| 8 | 8 | class Builder |
| 9 | 9 | { |
| 10 | 10 | public $appDir; |
| 11 | 11 | |
| 12 | - public function __construct (string $appDir) |
|
| 12 | + public function __construct(string $appDir) |
|
| 13 | 13 | { |
| 14 | - if (!is_dir ($appDir)) |
|
| 15 | - throw new \Exception ('Wrong $appDir param'); |
|
| 14 | + if (!is_dir($appDir)) |
|
| 15 | + throw new \Exception('Wrong $appDir param'); |
|
| 16 | 16 | |
| 17 | 17 | $this->appDir = $appDir; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function build (string $outputDir, string $iconPath = null, bool $union = true): array |
|
| 20 | + public function build(string $outputDir, string $iconPath = null, bool $union = true): array |
|
| 21 | 21 | { |
| 22 | - \VoidEngine\dir_clean ($outputDir .'/build'); |
|
| 23 | - \VoidEngine\dir_copy (CORE_DIR, $outputDir .'/build'); |
|
| 22 | + \VoidEngine\dir_clean($outputDir.'/build'); |
|
| 23 | + \VoidEngine\dir_copy(CORE_DIR, $outputDir.'/build'); |
|
| 24 | 24 | |
| 25 | - unlink ($outputDir .'/build/script.php'); |
|
| 26 | - unlink ($outputDir .'/build/VoidCore.exe'); |
|
| 25 | + unlink($outputDir.'/build/script.php'); |
|
| 26 | + unlink($outputDir.'/build/VoidCore.exe'); |
|
| 27 | 27 | |
| 28 | - \VoidEngine\dir_clean ($outputDir .'/build/qero-packages'); |
|
| 29 | - \VoidEngine\dir_copy (dirname ($this->appDir) .'/qero-packages', $outputDir .'/build/qero-packages'); |
|
| 30 | - \VoidEngine\dir_delete ($outputDir .'/build/qero-packages/winforms-php/VoidFramework'); |
|
| 28 | + \VoidEngine\dir_clean($outputDir.'/build/qero-packages'); |
|
| 29 | + \VoidEngine\dir_copy(dirname($this->appDir).'/qero-packages', $outputDir.'/build/qero-packages'); |
|
| 30 | + \VoidEngine\dir_delete($outputDir.'/build/qero-packages/winforms-php/VoidFramework'); |
|
| 31 | 31 | |
| 32 | - return \VoidEngine\EngineAdditions::compile ($outputDir .'/build/app.exe', $iconPath ?? dirname (__DIR__) .'/system/Icon.ico', self::optimizeCode (\VoidEngine\str_replace_assoc (file_get_contents (dirname (__DIR__) .'/system/preset.php'), [ |
|
| 33 | - '%VoidEngine%' => self::generateCode (self::getReferences (ENGINE_DIR .'/VoidEngine.php')), |
|
| 34 | - '%APP%' => base64_encode (gzdeflate (serialize ($union ? self::getFiles ($this->appDir) : []), 9)) |
|
| 32 | + return \VoidEngine\EngineAdditions::compile($outputDir.'/build/app.exe', $iconPath ?? dirname(__DIR__).'/system/Icon.ico', self::optimizeCode(\VoidEngine\str_replace_assoc(file_get_contents(dirname(__DIR__).'/system/preset.php'), [ |
|
| 33 | + '%VoidEngine%' => self::generateCode(self::getReferences(ENGINE_DIR.'/VoidEngine.php')), |
|
| 34 | + '%APP%' => base64_encode(gzdeflate(serialize($union ? self::getFiles($this->appDir) : []), 9)) |
|
| 35 | 35 | ]))/*, null, null, null, null, null, '', '', null, null*/); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public static function generateCode (array $references, bool $removeNamespaces = true): string |
|
| 38 | + public static function generateCode(array $references, bool $removeNamespaces = true): string |
|
| 39 | 39 | { |
| 40 | - $code = "/*\n\n\t". join ("\n\t", explode ("\n", file_get_contents (dirname (ENGINE_DIR) .'/license.txt'))) ."\n\n*/\n\n"; |
|
| 40 | + $code = "/*\n\n\t".join("\n\t", explode("\n", file_get_contents(dirname(ENGINE_DIR).'/license.txt')))."\n\n*/\n\n"; |
|
| 41 | 41 | |
| 42 | 42 | foreach ($references as $path) |
| 43 | - $code .= join (array_slice (array_map (function ($line) |
|
| 43 | + $code .= join(array_slice(array_map(function($line) |
|
| 44 | 44 | { |
| 45 | - return substr ($line, 0, 7) != 'require' ? $line : ''; |
|
| 46 | - }, file ($path)), 1)); |
|
| 45 | + return substr($line, 0, 7) != 'require' ? $line : ''; |
|
| 46 | + }, file($path)), 1)); |
|
| 47 | 47 | |
| 48 | 48 | return $removeNamespaces ? |
| 49 | - preg_replace ('/'. "\n" .'namespace [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*;'. "\n" .'/', "\n\n", $code) : $code; |
|
| 49 | + preg_replace ('/'."\n".'namespace [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*;'."\n".'/', "\n\n", $code) : $code; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - public static function getReferences (string $file, bool $parseExtensions = true): array |
|
| 52 | + public static function getReferences(string $file, bool $parseExtensions = true): array |
|
| 53 | 53 | { |
| 54 | 54 | $references = []; |
| 55 | 55 | |
| 56 | - foreach (file ($file) as $line) |
|
| 57 | - if (substr ($line, 0, 7) == 'require') |
|
| 56 | + foreach (file($file) as $line) |
|
| 57 | + if (substr($line, 0, 7) == 'require') |
|
| 58 | 58 | try |
| 59 | 59 | { |
| 60 | - $begin = strpos ($line, "'"); |
|
| 61 | - $end = strrpos ($line, "'") - $begin + 1; |
|
| 60 | + $begin = strpos($line, "'"); |
|
| 61 | + $end = strrpos($line, "'") - $begin + 1; |
|
| 62 | 62 | |
| 63 | - $references = array_merge ($references, self::getReferences (dirname ($file) .'/'. eval ('namespace VoidEngine; return '. substr ($line, $begin, $end) .';'), false)); |
|
| 63 | + $references = array_merge($references, self::getReferences(dirname($file).'/'.eval ('namespace VoidEngine; return '.substr($line, $begin, $end).';'), false)); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | catch (\Throwable $e) |
@@ -69,42 +69,42 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | if ($parseExtensions) |
| 72 | - if (is_dir (ENGINE_DIR .'/extensions') && is_array ($exts = scandir (ENGINE_DIR .'/extensions'))) |
|
| 72 | + if (is_dir(ENGINE_DIR.'/extensions') && is_array($exts = scandir(ENGINE_DIR.'/extensions'))) |
|
| 73 | 73 | foreach ($exts as $ext) |
| 74 | - if (is_dir (ENGINE_DIR .'/extensions/'. $ext) && file_exists ($ext = ENGINE_DIR .'/extensions/'. $ext .'/main.php')) |
|
| 75 | - $references = array_merge ($references, self::getReferences ($ext, false)); |
|
| 74 | + if (is_dir(ENGINE_DIR.'/extensions/'.$ext) && file_exists($ext = ENGINE_DIR.'/extensions/'.$ext.'/main.php')) |
|
| 75 | + $references = array_merge($references, self::getReferences($ext, false)); |
|
| 76 | 76 | |
| 77 | 77 | $references[] = $file; |
| 78 | 78 | |
| 79 | 79 | return $references; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public static function getFiles (string $path, string $prefixBlacklist = null, array $files = [], int $originalPathLength = -1): array |
|
| 82 | + public static function getFiles(string $path, string $prefixBlacklist = null, array $files = [], int $originalPathLength = -1): array |
|
| 83 | 83 | { |
| 84 | 84 | if ($originalPathLength == -1) |
| 85 | - $originalPathLength = strlen (dirname ($path)) + 1; |
|
| 85 | + $originalPathLength = strlen(dirname($path)) + 1; |
|
| 86 | 86 | |
| 87 | - $len = strlen ($prefixBlacklist); |
|
| 87 | + $len = strlen($prefixBlacklist); |
|
| 88 | 88 | |
| 89 | - foreach (array_slice (scandir ($path), 2) as $name) |
|
| 90 | - if ($prefixBlacklist === null || substr ($path .'/'. $name, $originalPathLength, $len) != $prefixBlacklist) |
|
| 89 | + foreach (array_slice(scandir($path), 2) as $name) |
|
| 90 | + if ($prefixBlacklist === null || substr($path.'/'.$name, $originalPathLength, $len) != $prefixBlacklist) |
|
| 91 | 91 | { |
| 92 | - if (is_dir ($file = $path .'/'. $name)) |
|
| 93 | - $files = self::getFiles ($file, $prefixBlacklist, $files, $originalPathLength); |
|
| 92 | + if (is_dir($file = $path.'/'.$name)) |
|
| 93 | + $files = self::getFiles($file, $prefixBlacklist, $files, $originalPathLength); |
|
| 94 | 94 | |
| 95 | - else $files[substr ($file, $originalPathLength)] = file_get_contents ($file); |
|
| 95 | + else $files[substr($file, $originalPathLength)] = file_get_contents($file); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $files; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - public static function optimizeCode (string $code): string |
|
| 101 | + public static function optimizeCode(string $code): string |
|
| 102 | 102 | { |
| 103 | - $tokens = token_get_all ('<?php '. $code); |
|
| 103 | + $tokens = token_get_all('<?php '.$code); |
|
| 104 | 104 | $return = ''; |
| 105 | 105 | |
| 106 | 106 | foreach ($tokens as $id => $token) |
| 107 | - if (is_string ($token)) |
|
| 107 | + if (is_string($token)) |
|
| 108 | 108 | $return .= $token; |
| 109 | 109 | |
| 110 | 110 | else |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | break; |
| 119 | 119 | |
| 120 | 120 | case T_WHITESPACE: |
| 121 | - if (!isset ($tokens[$id + 1]) || !is_array ($tokens[$id + 1]) || $tokens[$id + 1][0] != T_WHITESPACE) |
|
| 121 | + if (!isset ($tokens[$id + 1]) || !is_array($tokens[$id + 1]) || $tokens[$id + 1][0] != T_WHITESPACE) |
|
| 122 | 122 | $return .= ' '; |
| 123 | 123 | |
| 124 | 124 | break; |
@@ -130,6 +130,6 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return substr ($return, 6); |
|
| 133 | + return substr($return, 6); |
|
| 134 | 134 | } |
| 135 | 135 | } |
@@ -2,8 +2,9 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace VoidBuilder; |
| 4 | 4 | |
| 5 | -if (!defined ('VoidBuilder\ENGINE_DIR') && defined ('VoidEngine\ENGINE_DIR')) |
|
| 5 | +if (!defined ('VoidBuilder\ENGINE_DIR') && defined ('VoidEngine\ENGINE_DIR')) { |
|
| 6 | 6 | define ('VoidBuilder\ENGINE_DIR', \VoidEngine\ENGINE_DIR); |
| 7 | +} |
|
| 7 | 8 | |
| 8 | 9 | class Builder |
| 9 | 10 | { |
@@ -11,8 +12,9 @@ discard block |
||
| 11 | 12 | |
| 12 | 13 | public function __construct (string $appDir) |
| 13 | 14 | { |
| 14 | - if (!is_dir ($appDir)) |
|
| 15 | - throw new \Exception ('Wrong $appDir param'); |
|
| 15 | + if (!is_dir ($appDir)) { |
|
| 16 | + throw new \Exception ('Wrong $appDir param'); |
|
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | $this->appDir = $appDir; |
| 18 | 20 | } |
@@ -39,10 +41,11 @@ discard block |
||
| 39 | 41 | { |
| 40 | 42 | $code = "/*\n\n\t". join ("\n\t", explode ("\n", file_get_contents (dirname (ENGINE_DIR) .'/license.txt'))) ."\n\n*/\n\n"; |
| 41 | 43 | |
| 42 | - foreach ($references as $path) |
|
| 43 | - $code .= join (array_slice (array_map (function ($line) |
|
| 44 | + foreach ($references as $path) { |
|
| 45 | + $code .= join (array_slice (array_map (function ($line) |
|
| 44 | 46 | { |
| 45 | 47 | return substr ($line, 0, 7) != 'require' ? $line : ''; |
| 48 | + } |
|
| 46 | 49 | }, file ($path)), 1)); |
| 47 | 50 | |
| 48 | 51 | return $removeNamespaces ? |
@@ -53,26 +56,26 @@ discard block |
||
| 53 | 56 | { |
| 54 | 57 | $references = []; |
| 55 | 58 | |
| 56 | - foreach (file ($file) as $line) |
|
| 57 | - if (substr ($line, 0, 7) == 'require') |
|
| 59 | + foreach (file ($file) as $line) { |
|
| 60 | + if (substr ($line, 0, 7) == 'require') |
|
| 58 | 61 | try |
| 59 | 62 | { |
| 60 | 63 | $begin = strpos ($line, "'"); |
| 64 | + } |
|
| 61 | 65 | $end = strrpos ($line, "'") - $begin + 1; |
| 62 | 66 | |
| 63 | 67 | $references = array_merge ($references, self::getReferences (dirname ($file) .'/'. eval ('namespace VoidEngine; return '. substr ($line, $begin, $end) .';'), false)); |
| 64 | - } |
|
| 65 | - |
|
| 66 | - catch (\Throwable $e) |
|
| 68 | + } catch (\Throwable $e) |
|
| 67 | 69 | { |
| 68 | 70 | continue; |
| 69 | 71 | } |
| 70 | 72 | |
| 71 | - if ($parseExtensions) |
|
| 72 | - if (is_dir (ENGINE_DIR .'/extensions') && is_array ($exts = scandir (ENGINE_DIR .'/extensions'))) |
|
| 73 | + if ($parseExtensions) { |
|
| 74 | + if (is_dir (ENGINE_DIR .'/extensions') && is_array ($exts = scandir (ENGINE_DIR .'/extensions'))) |
|
| 73 | 75 | foreach ($exts as $ext) |
| 74 | 76 | if (is_dir (ENGINE_DIR .'/extensions/'. $ext) && file_exists ($ext = ENGINE_DIR .'/extensions/'. $ext .'/main.php')) |
| 75 | 77 | $references = array_merge ($references, self::getReferences ($ext, false)); |
| 78 | + } |
|
| 76 | 79 | |
| 77 | 80 | $references[] = $file; |
| 78 | 81 | |
@@ -81,18 +84,22 @@ discard block |
||
| 81 | 84 | |
| 82 | 85 | public static function getFiles (string $path, string $prefixBlacklist = null, array $files = [], int $originalPathLength = -1): array |
| 83 | 86 | { |
| 84 | - if ($originalPathLength == -1) |
|
| 85 | - $originalPathLength = strlen (dirname ($path)) + 1; |
|
| 87 | + if ($originalPathLength == -1) { |
|
| 88 | + $originalPathLength = strlen (dirname ($path)) + 1; |
|
| 89 | + } |
|
| 86 | 90 | |
| 87 | 91 | $len = strlen ($prefixBlacklist); |
| 88 | 92 | |
| 89 | - foreach (array_slice (scandir ($path), 2) as $name) |
|
| 90 | - if ($prefixBlacklist === null || substr ($path .'/'. $name, $originalPathLength, $len) != $prefixBlacklist) |
|
| 93 | + foreach (array_slice (scandir ($path), 2) as $name) { |
|
| 94 | + if ($prefixBlacklist === null || substr ($path .'/'. $name, $originalPathLength, $len) != $prefixBlacklist) |
|
| 91 | 95 | { |
| 92 | 96 | if (is_dir ($file = $path .'/'. $name)) |
| 93 | 97 | $files = self::getFiles ($file, $prefixBlacklist, $files, $originalPathLength); |
| 98 | + } |
|
| 94 | 99 | |
| 95 | - else $files[substr ($file, $originalPathLength)] = file_get_contents ($file); |
|
| 100 | + else { |
|
| 101 | + $files[substr ($file, $originalPathLength)] = file_get_contents ($file); |
|
| 102 | + } |
|
| 96 | 103 | } |
| 97 | 104 | |
| 98 | 105 | return $files; |
@@ -103,9 +110,10 @@ discard block |
||
| 103 | 110 | $tokens = token_get_all ('<?php '. $code); |
| 104 | 111 | $return = ''; |
| 105 | 112 | |
| 106 | - foreach ($tokens as $id => $token) |
|
| 107 | - if (is_string ($token)) |
|
| 113 | + foreach ($tokens as $id => $token) { |
|
| 114 | + if (is_string ($token)) |
|
| 108 | 115 | $return .= $token; |
| 116 | + } |
|
| 109 | 117 | |
| 110 | 118 | else |
| 111 | 119 | { |
@@ -118,8 +126,9 @@ discard block |
||
| 118 | 126 | break; |
| 119 | 127 | |
| 120 | 128 | case T_WHITESPACE: |
| 121 | - if (!isset ($tokens[$id + 1]) || !is_array ($tokens[$id + 1]) || $tokens[$id + 1][0] != T_WHITESPACE) |
|
| 122 | - $return .= ' '; |
|
| 129 | + if (!isset ($tokens[$id + 1]) || !is_array ($tokens[$id + 1]) || $tokens[$id + 1][0] != T_WHITESPACE) { |
|
| 130 | + $return .= ' '; |
|
| 131 | + } |
|
| 123 | 132 | |
| 124 | 133 | break; |
| 125 | 134 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param array $commands - список команд |
| 19 | 19 | * [@param DefaultCommand $defaultCommand = null] - объект дефолтной команды |
| 20 | 20 | */ |
| 21 | - public function __construct (array $commands, DefaultCommand $defaultCommand = null) |
|
| 21 | + public function __construct(array $commands, DefaultCommand $defaultCommand = null) |
|
| 22 | 22 | { |
| 23 | 23 | $this->locale = new Locale; |
| 24 | 24 | $this->defaultCommand = $defaultCommand; |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | if ($command instanceof Command) |
| 28 | 28 | $this->commands[$command->name] = $command; |
| 29 | 29 | |
| 30 | - else throw new \Exception ($this->locale->command_type_exception); |
|
| 30 | + else throw new \Exception($this->locale->command_type_exception); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return Manager - возвращает сам себя |
| 39 | 39 | */ |
| 40 | - public function setLocale (Locale $locale): Manager |
|
| 40 | + public function setLocale(Locale $locale): Manager |
|
| 41 | 41 | { |
| 42 | 42 | $this->locale = $locale; |
| 43 | 43 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return Manager - возвращает сам себя |
| 53 | 53 | */ |
| 54 | - public function setDefault (DefaultCommand $defaultCommand): Manager |
|
| 54 | + public function setDefault(DefaultCommand $defaultCommand): Manager |
|
| 55 | 55 | { |
| 56 | 56 | $this->defaultCommand = $defaultCommand; |
| 57 | 57 | |
@@ -63,31 +63,31 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @param array $args - список аргументов консоли |
| 65 | 65 | */ |
| 66 | - public function execute (array $args) |
|
| 66 | + public function execute(array $args) |
|
| 67 | 67 | { |
| 68 | - $args = array_values ($args); |
|
| 68 | + $args = array_values($args); |
|
| 69 | 69 | |
| 70 | 70 | if (!isset ($args[0])) |
| 71 | 71 | { |
| 72 | 72 | if ($this->defaultCommand !== null) |
| 73 | - return $this->defaultCommand->execute ($args); |
|
| 73 | + return $this->defaultCommand->execute($args); |
|
| 74 | 74 | |
| 75 | - else throw new \Exception ($this->locale->command_undefined_error); |
|
| 75 | + else throw new \Exception($this->locale->command_undefined_error); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $name = $args[0]; |
| 79 | - $args = array_slice ($args, 1); |
|
| 79 | + $args = array_slice($args, 1); |
|
| 80 | 80 | |
| 81 | 81 | if (!isset ($this->commands[$name])) |
| 82 | 82 | { |
| 83 | 83 | foreach ($this->commands as $command) |
| 84 | - if (in_array ($name, $command->aliases)) |
|
| 85 | - return $command->execute ($args); |
|
| 84 | + if (in_array($name, $command->aliases)) |
|
| 85 | + return $command->execute($args); |
|
| 86 | 86 | |
| 87 | 87 | return $this->defaultCommand !== null ? |
| 88 | - $this->defaultCommand->execute ($args) : false; |
|
| 88 | + $this->defaultCommand->execute($args) : false; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - return $this->commands[$name]->execute ($args); |
|
| 91 | + return $this->commands[$name]->execute($args); |
|
| 92 | 92 | } |
| 93 | 93 | } |
@@ -23,11 +23,14 @@ discard block |
||
| 23 | 23 | $this->locale = new Locale; |
| 24 | 24 | $this->defaultCommand = $defaultCommand; |
| 25 | 25 | |
| 26 | - foreach ($commands as $command) |
|
| 27 | - if ($command instanceof Command) |
|
| 26 | + foreach ($commands as $command) { |
|
| 27 | + if ($command instanceof Command) |
|
| 28 | 28 | $this->commands[$command->name] = $command; |
| 29 | + } |
|
| 29 | 30 | |
| 30 | - else throw new \Exception ($this->locale->command_type_exception); |
|
| 31 | + else { |
|
| 32 | + throw new \Exception ($this->locale->command_type_exception); |
|
| 33 | + } |
|
| 31 | 34 | } |
| 32 | 35 | |
| 33 | 36 | /** |
@@ -69,10 +72,11 @@ discard block |
||
| 69 | 72 | |
| 70 | 73 | if (!isset ($args[0])) |
| 71 | 74 | { |
| 72 | - if ($this->defaultCommand !== null) |
|
| 73 | - return $this->defaultCommand->execute ($args); |
|
| 74 | - |
|
| 75 | - else throw new \Exception ($this->locale->command_undefined_error); |
|
| 75 | + if ($this->defaultCommand !== null) { |
|
| 76 | + return $this->defaultCommand->execute ($args); |
|
| 77 | + } else { |
|
| 78 | + throw new \Exception ($this->locale->command_undefined_error); |
|
| 79 | + } |
|
| 76 | 80 | } |
| 77 | 81 | |
| 78 | 82 | $name = $args[0]; |
@@ -80,9 +84,10 @@ discard block |
||
| 80 | 84 | |
| 81 | 85 | if (!isset ($this->commands[$name])) |
| 82 | 86 | { |
| 83 | - foreach ($this->commands as $command) |
|
| 84 | - if (in_array ($name, $command->aliases)) |
|
| 87 | + foreach ($this->commands as $command) { |
|
| 88 | + if (in_array ($name, $command->aliases)) |
|
| 85 | 89 | return $command->execute ($args); |
| 90 | + } |
|
| 86 | 91 | |
| 87 | 92 | return $this->defaultCommand !== null ? |
| 88 | 93 | $this->defaultCommand->execute ($args) : false; |
@@ -10,5 +10,5 @@ |
||
| 10 | 10 | /** |
| 11 | 11 | * Парсер значений |
| 12 | 12 | */ |
| 13 | - public function parse (array &$args); |
|
| 13 | + public function parse(array &$args); |
|
| 14 | 14 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param string $name - имя флага |
| 18 | 18 | */ |
| 19 | - public function __construct (string $name) |
|
| 19 | + public function __construct(string $name) |
|
| 20 | 20 | { |
| 21 | 21 | $this->names = [$name]; |
| 22 | 22 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return Flag - возвращает сам себя |
| 30 | 30 | */ |
| 31 | - public function setLocale (Locale $locale): Param |
|
| 31 | + public function setLocale(Locale $locale): Param |
|
| 32 | 32 | { |
| 33 | 33 | $this->locale = $locale; |
| 34 | 34 | |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return Flag - возвращает сам себя |
| 44 | 44 | */ |
| 45 | - public function addAliase (string $name) |
|
| 45 | + public function addAliase(string $name) |
|
| 46 | 46 | { |
| 47 | - if (array_search ($name, $this->names) !== false) |
|
| 48 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 47 | + if (array_search($name, $this->names) !== false) |
|
| 48 | + throw new \Exception($this->locale->aliase_exists_exception); |
|
| 49 | 49 | |
| 50 | 50 | $this->names[] = $name; |
| 51 | 51 | |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * Возвращает состояние флага |
| 61 | 61 | */ |
| 62 | - public function parse (array &$args) |
|
| 62 | + public function parse(array &$args) |
|
| 63 | 63 | { |
| 64 | - $args = array_values ($args); |
|
| 64 | + $args = array_values($args); |
|
| 65 | 65 | |
| 66 | 66 | foreach ($this->names as $name) |
| 67 | - if (($key = array_search ($name, $args)) !== false) |
|
| 67 | + if (($key = array_search($name, $args)) !== false) |
|
| 68 | 68 | { |
| 69 | 69 | unset ($args[$key]); |
| 70 | - $args = array_values ($args); |
|
| 70 | + $args = array_values($args); |
|
| 71 | 71 | |
| 72 | - while ($this->parse ($args) !== false); |
|
| 72 | + while ($this->parse($args) !== false); |
|
| 73 | 73 | |
| 74 | 74 | return true; |
| 75 | 75 | } |
@@ -44,8 +44,9 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function addAliase (string $name) |
| 46 | 46 | { |
| 47 | - if (array_search ($name, $this->names) !== false) |
|
| 48 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 47 | + if (array_search ($name, $this->names) !== false) { |
|
| 48 | + throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 49 | + } |
|
| 49 | 50 | |
| 50 | 51 | $this->names[] = $name; |
| 51 | 52 | |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | { |
| 64 | 65 | $args = array_values ($args); |
| 65 | 66 | |
| 66 | - foreach ($this->names as $name) |
|
| 67 | - if (($key = array_search ($name, $args)) !== false) |
|
| 67 | + foreach ($this->names as $name) { |
|
| 68 | + if (($key = array_search ($name, $args)) !== false) |
|
| 68 | 69 | { |
| 69 | 70 | unset ($args[$key]); |
| 71 | + } |
|
| 70 | 72 | $args = array_values ($args); |
| 71 | 73 | |
| 72 | 74 | while ($this->parse ($args) !== false); |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * [@param string $defaultValue = null] - значение сеттера по умолчанию |
| 23 | 23 | * [@param bool $required = false] - обязательно ли указание сеттера |
| 24 | 24 | */ |
| 25 | - public function __construct (string $name, string $separator = '=', string $defaultValue = null, bool $required = false) |
|
| 25 | + public function __construct(string $name, string $separator = '=', string $defaultValue = null, bool $required = false) |
|
| 26 | 26 | { |
| 27 | 27 | $this->names = [$name]; |
| 28 | 28 | $this->separator = $separator; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return Param - возвращает сам себя |
| 41 | 41 | */ |
| 42 | - public function setLocale (Locale $locale): Param |
|
| 42 | + public function setLocale(Locale $locale): Param |
|
| 43 | 43 | { |
| 44 | 44 | $this->locale = $locale; |
| 45 | 45 | |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return Param - возвращает сам себя |
| 55 | 55 | */ |
| 56 | - public function addAliase (string $name) |
|
| 56 | + public function addAliase(string $name) |
|
| 57 | 57 | { |
| 58 | - if (array_search ($name, $this->names) !== false) |
|
| 59 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 58 | + if (array_search($name, $this->names) !== false) |
|
| 59 | + throw new \Exception($this->locale->aliase_exists_exception); |
|
| 60 | 60 | |
| 61 | 61 | $this->names[] = $name; |
| 62 | 62 | |
@@ -70,26 +70,26 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * Возвращает найденый параметр или массив найдёных параметров, если их было указано несколько |
| 72 | 72 | */ |
| 73 | - public function parse (array &$args) |
|
| 73 | + public function parse(array &$args) |
|
| 74 | 74 | { |
| 75 | - $args = array_values ($args); |
|
| 76 | - $l = strlen ($this->separator); |
|
| 75 | + $args = array_values($args); |
|
| 76 | + $l = strlen($this->separator); |
|
| 77 | 77 | |
| 78 | 78 | foreach ($this->names as $name) |
| 79 | 79 | foreach ($args as $id => $arg) |
| 80 | - if (substr ($arg, 0, ($pos = strlen ($name) + $l)) == $name . $this->separator) |
|
| 80 | + if (substr($arg, 0, ($pos = strlen($name) + $l)) == $name.$this->separator) |
|
| 81 | 81 | { |
| 82 | - $param = [substr ($arg, $pos)]; |
|
| 82 | + $param = [substr($arg, $pos)]; |
|
| 83 | 83 | |
| 84 | 84 | unset ($args[$id]); |
| 85 | - $args = array_values ($args); |
|
| 85 | + $args = array_values($args); |
|
| 86 | 86 | |
| 87 | 87 | try |
| 88 | 88 | { |
| 89 | - while (($altParam = $this->parse ($args)) !== $this->defaultValue) |
|
| 89 | + while (($altParam = $this->parse($args)) !== $this->defaultValue) |
|
| 90 | 90 | { |
| 91 | - if (is_array ($altParam)) |
|
| 92 | - $param = array_merge ($param, $altParam); |
|
| 91 | + if (is_array($altParam)) |
|
| 92 | + $param = array_merge($param, $altParam); |
|
| 93 | 93 | |
| 94 | 94 | else $param[] = $altParam; |
| 95 | 95 | } |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | catch (\Throwable $e) {} |
| 99 | 99 | |
| 100 | - return sizeof ($param) == 1 ? |
|
| 100 | + return sizeof($param) == 1 ? |
|
| 101 | 101 | $param[0] : $param; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | if ($this->required) |
| 105 | - throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 105 | + throw new \Exception(str_replace('%param_name%', current($this->names), $this->locale->undefined_param_exception)); |
|
| 106 | 106 | |
| 107 | 107 | return $this->defaultValue; |
| 108 | 108 | } |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function addAliase (string $name) |
| 57 | 57 | { |
| 58 | - if (array_search ($name, $this->names) !== false) |
|
| 59 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 58 | + if (array_search ($name, $this->names) !== false) { |
|
| 59 | + throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 60 | + } |
|
| 60 | 61 | |
| 61 | 62 | $this->names[] = $name; |
| 62 | 63 | |
@@ -75,11 +76,12 @@ discard block |
||
| 75 | 76 | $args = array_values ($args); |
| 76 | 77 | $l = strlen ($this->separator); |
| 77 | 78 | |
| 78 | - foreach ($this->names as $name) |
|
| 79 | - foreach ($args as $id => $arg) |
|
| 79 | + foreach ($this->names as $name) { |
|
| 80 | + foreach ($args as $id => $arg) |
|
| 80 | 81 | if (substr ($arg, 0, ($pos = strlen ($name) + $l)) == $name . $this->separator) |
| 81 | 82 | { |
| 82 | 83 | $param = [substr ($arg, $pos)]; |
| 84 | + } |
|
| 83 | 85 | |
| 84 | 86 | unset ($args[$id]); |
| 85 | 87 | $args = array_values ($args); |
@@ -88,21 +90,21 @@ discard block |
||
| 88 | 90 | { |
| 89 | 91 | while (($altParam = $this->parse ($args)) !== $this->defaultValue) |
| 90 | 92 | { |
| 91 | - if (is_array ($altParam)) |
|
| 92 | - $param = array_merge ($param, $altParam); |
|
| 93 | - |
|
| 94 | - else $param[] = $altParam; |
|
| 93 | + if (is_array ($altParam)) { |
|
| 94 | + $param = array_merge ($param, $altParam); |
|
| 95 | + } else { |
|
| 96 | + $param[] = $altParam; |
|
| 97 | + } |
|
| 95 | 98 | } |
| 96 | - } |
|
| 97 | - |
|
| 98 | - catch (\Throwable $e) {} |
|
| 99 | + } catch (\Throwable $e) {} |
|
| 99 | 100 | |
| 100 | 101 | return sizeof ($param) == 1 ? |
| 101 | 102 | $param[0] : $param; |
| 102 | 103 | } |
| 103 | 104 | |
| 104 | - if ($this->required) |
|
| 105 | - throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 105 | + if ($this->required) { |
|
| 106 | + throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 107 | + } |
|
| 106 | 108 | |
| 107 | 109 | return $this->defaultValue; |
| 108 | 110 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * [@param string $defaultValue = null] - значение параметра по умолчанию |
| 21 | 21 | * [@param bool $required = false] - обязательно ли указание параметра |
| 22 | 22 | */ |
| 23 | - public function __construct (string $name, string $defaultValue = null, bool $required = false) |
|
| 23 | + public function __construct(string $name, string $defaultValue = null, bool $required = false) |
|
| 24 | 24 | { |
| 25 | 25 | $this->names = [$name]; |
| 26 | 26 | $this->defaultValue = $defaultValue; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return Param - возвращает сам себя |
| 38 | 38 | */ |
| 39 | - public function setLocale (Locale $locale): Param |
|
| 39 | + public function setLocale(Locale $locale): Param |
|
| 40 | 40 | { |
| 41 | 41 | $this->locale = $locale; |
| 42 | 42 | |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @return Param - возвращает сам себя |
| 52 | 52 | */ |
| 53 | - public function addAliase (string $name) |
|
| 53 | + public function addAliase(string $name) |
|
| 54 | 54 | { |
| 55 | - if (array_search ($name, $this->names) !== false) |
|
| 56 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 55 | + if (array_search($name, $this->names) !== false) |
|
| 56 | + throw new \Exception($this->locale->aliase_exists_exception); |
|
| 57 | 57 | |
| 58 | 58 | $this->names[] = $name; |
| 59 | 59 | |
@@ -67,27 +67,27 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * Возвращает найденый параметр или массив найдёных параметров, если их было указано несколько |
| 69 | 69 | */ |
| 70 | - public function parse (array &$args) |
|
| 70 | + public function parse(array &$args) |
|
| 71 | 71 | { |
| 72 | - $args = array_values ($args); |
|
| 72 | + $args = array_values($args); |
|
| 73 | 73 | |
| 74 | 74 | foreach ($this->names as $name) |
| 75 | - if (($key = array_search ($name, $args)) !== false) |
|
| 75 | + if (($key = array_search($name, $args)) !== false) |
|
| 76 | 76 | { |
| 77 | 77 | if (!isset ($args[$key + 1])) |
| 78 | - throw new \Exception ($this->locale->unselected_value_exception); |
|
| 78 | + throw new \Exception($this->locale->unselected_value_exception); |
|
| 79 | 79 | |
| 80 | 80 | $param = [$args[$key + 1]]; |
| 81 | 81 | |
| 82 | 82 | unset ($args[$key], $args[$key + 1]); |
| 83 | - $args = array_values ($args); |
|
| 83 | + $args = array_values($args); |
|
| 84 | 84 | |
| 85 | 85 | try |
| 86 | 86 | { |
| 87 | - while (($altParam = $this->parse ($args)) !== $this->defaultValue) |
|
| 87 | + while (($altParam = $this->parse($args)) !== $this->defaultValue) |
|
| 88 | 88 | { |
| 89 | - if (is_array ($altParam)) |
|
| 90 | - $param = array_merge ($param, $altParam); |
|
| 89 | + if (is_array($altParam)) |
|
| 90 | + $param = array_merge($param, $altParam); |
|
| 91 | 91 | |
| 92 | 92 | else $param[] = $altParam; |
| 93 | 93 | } |
@@ -95,12 +95,12 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | catch (\Throwable $e) {} |
| 97 | 97 | |
| 98 | - return sizeof ($param) == 1 ? |
|
| 98 | + return sizeof($param) == 1 ? |
|
| 99 | 99 | $param[0] : $param; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | if ($this->required) |
| 103 | - throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 103 | + throw new \Exception(str_replace('%param_name%', current($this->names), $this->locale->undefined_param_exception)); |
|
| 104 | 104 | |
| 105 | 105 | return $this->defaultValue; |
| 106 | 106 | } |
@@ -52,8 +52,9 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function addAliase (string $name) |
| 54 | 54 | { |
| 55 | - if (array_search ($name, $this->names) !== false) |
|
| 56 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 55 | + if (array_search ($name, $this->names) !== false) { |
|
| 56 | + throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 57 | + } |
|
| 57 | 58 | |
| 58 | 59 | $this->names[] = $name; |
| 59 | 60 | |
@@ -71,11 +72,12 @@ discard block |
||
| 71 | 72 | { |
| 72 | 73 | $args = array_values ($args); |
| 73 | 74 | |
| 74 | - foreach ($this->names as $name) |
|
| 75 | - if (($key = array_search ($name, $args)) !== false) |
|
| 75 | + foreach ($this->names as $name) { |
|
| 76 | + if (($key = array_search ($name, $args)) !== false) |
|
| 76 | 77 | { |
| 77 | 78 | if (!isset ($args[$key + 1])) |
| 78 | 79 | throw new \Exception ($this->locale->unselected_value_exception); |
| 80 | + } |
|
| 79 | 81 | |
| 80 | 82 | $param = [$args[$key + 1]]; |
| 81 | 83 | |
@@ -86,21 +88,21 @@ discard block |
||
| 86 | 88 | { |
| 87 | 89 | while (($altParam = $this->parse ($args)) !== $this->defaultValue) |
| 88 | 90 | { |
| 89 | - if (is_array ($altParam)) |
|
| 90 | - $param = array_merge ($param, $altParam); |
|
| 91 | - |
|
| 92 | - else $param[] = $altParam; |
|
| 91 | + if (is_array ($altParam)) { |
|
| 92 | + $param = array_merge ($param, $altParam); |
|
| 93 | + } else { |
|
| 94 | + $param[] = $altParam; |
|
| 95 | + } |
|
| 93 | 96 | } |
| 94 | - } |
|
| 95 | - |
|
| 96 | - catch (\Throwable $e) {} |
|
| 97 | + } catch (\Throwable $e) {} |
|
| 97 | 98 | |
| 98 | 99 | return sizeof ($param) == 1 ? |
| 99 | 100 | $param[0] : $param; |
| 100 | 101 | } |
| 101 | 102 | |
| 102 | - if ($this->required) |
|
| 103 | - throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 103 | + if ($this->required) { |
|
| 104 | + throw new \Exception (str_replace ('%param_name%', current ($this->names), $this->locale->undefined_param_exception)); |
|
| 105 | + } |
|
| 104 | 106 | |
| 105 | 107 | return $this->defaultValue; |
| 106 | 108 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param string $name - имя команды |
| 22 | 22 | * [@param \Closure $callable = null] - анонимная функция для выполнения |
| 23 | 23 | */ |
| 24 | - public function __construct (string $name, \Closure $callable = null) |
|
| 24 | + public function __construct(string $name, \Closure $callable = null) |
|
| 25 | 25 | { |
| 26 | 26 | $this->name = $name; |
| 27 | 27 | $this->locale = new Locale; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @return Command - возвращает сам себя |
| 39 | 39 | */ |
| 40 | - public function setLocale (Locale $locale): Command |
|
| 40 | + public function setLocale(Locale $locale): Command |
|
| 41 | 41 | { |
| 42 | 42 | $this->locale = $locale; |
| 43 | 43 | |
@@ -51,13 +51,13 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @return Command - возвращает сам себя |
| 53 | 53 | */ |
| 54 | - public function addParams (array $params): Command |
|
| 54 | + public function addParams(array $params): Command |
|
| 55 | 55 | { |
| 56 | 56 | foreach ($params as $param) |
| 57 | 57 | if ($param instanceof Parameter) |
| 58 | - $this->params[current ($param->names)] = $param; |
|
| 58 | + $this->params[current($param->names)] = $param; |
|
| 59 | 59 | |
| 60 | - else throw new \Exception ($this->locale->param_type_exception); |
|
| 60 | + else throw new \Exception($this->locale->param_type_exception); |
|
| 61 | 61 | |
| 62 | 62 | return $this; |
| 63 | 63 | } |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return Command - возвращает сам себя |
| 71 | 71 | */ |
| 72 | - public function addAliase (string $name) |
|
| 72 | + public function addAliase(string $name) |
|
| 73 | 73 | { |
| 74 | - if (array_search ($name, $this->aliases) !== false) |
|
| 75 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 74 | + if (array_search($name, $this->aliases) !== false) |
|
| 75 | + throw new \Exception($this->locale->aliase_exists_exception); |
|
| 76 | 76 | |
| 77 | 77 | $this->aliases[] = $name; |
| 78 | 78 | |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * @return array - возвращает ассоциативный массив [параметр] => [значение] |
| 88 | 88 | */ |
| 89 | - public function getParams (array &$args): array |
|
| 89 | + public function getParams(array &$args): array |
|
| 90 | 90 | { |
| 91 | - $params = array_combine (array_keys ($this->params), array_fill (0, sizeof ($this->params), null)); |
|
| 91 | + $params = array_combine(array_keys($this->params), array_fill(0, sizeof($this->params), null)); |
|
| 92 | 92 | |
| 93 | 93 | foreach ($this->params as $name => $param) |
| 94 | - $params[$name] = $param->parse ($args); |
|
| 94 | + $params[$name] = $param->parse($args); |
|
| 95 | 95 | |
| 96 | 96 | return $params; |
| 97 | 97 | } |
@@ -101,15 +101,15 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @param array &$args - аргументы команды |
| 103 | 103 | */ |
| 104 | - public function execute (array &$args) |
|
| 104 | + public function execute(array &$args) |
|
| 105 | 105 | { |
| 106 | 106 | if ($this->callable instanceof \Closure) |
| 107 | 107 | { |
| 108 | - $params = $this->getParams ($args); |
|
| 108 | + $params = $this->getParams($args); |
|
| 109 | 109 | |
| 110 | - return $this->callable->call ($this, array_values ($args), $params); |
|
| 110 | + return $this->callable->call($this, array_values($args), $params); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - throw new \Exception ($this->locale->execution_error); |
|
| 113 | + throw new \Exception($this->locale->execution_error); |
|
| 114 | 114 | } |
| 115 | 115 | } |
@@ -26,8 +26,9 @@ discard block |
||
| 26 | 26 | $this->name = $name; |
| 27 | 27 | $this->locale = new Locale; |
| 28 | 28 | |
| 29 | - if ($callable !== null) |
|
| 30 | - $this->callable = $callable; |
|
| 29 | + if ($callable !== null) { |
|
| 30 | + $this->callable = $callable; |
|
| 31 | + } |
|
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | /** |
@@ -53,11 +54,14 @@ discard block |
||
| 53 | 54 | */ |
| 54 | 55 | public function addParams (array $params): Command |
| 55 | 56 | { |
| 56 | - foreach ($params as $param) |
|
| 57 | - if ($param instanceof Parameter) |
|
| 57 | + foreach ($params as $param) { |
|
| 58 | + if ($param instanceof Parameter) |
|
| 58 | 59 | $this->params[current ($param->names)] = $param; |
| 60 | + } |
|
| 59 | 61 | |
| 60 | - else throw new \Exception ($this->locale->param_type_exception); |
|
| 62 | + else { |
|
| 63 | + throw new \Exception ($this->locale->param_type_exception); |
|
| 64 | + } |
|
| 61 | 65 | |
| 62 | 66 | return $this; |
| 63 | 67 | } |
@@ -71,8 +75,9 @@ discard block |
||
| 71 | 75 | */ |
| 72 | 76 | public function addAliase (string $name) |
| 73 | 77 | { |
| 74 | - if (array_search ($name, $this->aliases) !== false) |
|
| 75 | - throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 78 | + if (array_search ($name, $this->aliases) !== false) { |
|
| 79 | + throw new \Exception ($this->locale->aliase_exists_exception); |
|
| 80 | + } |
|
| 76 | 81 | |
| 77 | 82 | $this->aliases[] = $name; |
| 78 | 83 | |
@@ -90,8 +95,9 @@ discard block |
||
| 90 | 95 | { |
| 91 | 96 | $params = array_combine (array_keys ($this->params), array_fill (0, sizeof ($this->params), null)); |
| 92 | 97 | |
| 93 | - foreach ($this->params as $name => $param) |
|
| 94 | - $params[$name] = $param->parse ($args); |
|
| 98 | + foreach ($this->params as $name => $param) { |
|
| 99 | + $params[$name] = $param->parse ($args); |
|
| 100 | + } |
|
| 95 | 101 | |
| 96 | 102 | return $params; |
| 97 | 103 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | * |
| 14 | 14 | * [@param \Closure $callable = null] - анонимная функция для выполнения |
| 15 | 15 | */ |
| 16 | - public function __construct (\Closure $callable = null) |
|
| 16 | + public function __construct(\Closure $callable = null) |
|
| 17 | 17 | { |
| 18 | 18 | if ($callable !== null) |
| 19 | 19 | $this->callable = $callable; |
@@ -15,7 +15,8 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | public function __construct (\Closure $callable = null) |
| 17 | 17 | { |
| 18 | - if ($callable !== null) |
|
| 19 | - $this->callable = $callable; |
|
| 18 | + if ($callable !== null) { |
|
| 19 | + $this->callable = $callable; |
|
| 20 | + } |
|
| 20 | 21 | } |
| 21 | 22 | } |