@@ -19,9 +19,9 @@ |
||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | use FileHelper { |
| 22 | - delete as protected deleteFile; |
|
| 23 | - FileHelper::copy insteadof DirectoryHelper; |
|
| 24 | - FileHelper::move insteadof DirectoryHelper; |
|
| 22 | + delete as protected deleteFile; |
|
| 23 | + FileHelper::copy insteadof DirectoryHelper; |
|
| 24 | + FileHelper::move insteadof DirectoryHelper; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public static function delete(string $path):bool |
| 36 | 36 | { |
| 37 | - if (($path=Path::format($path)) !== null) { |
|
| 37 | + if (($path = Path::format($path)) !== null) { |
|
| 38 | 38 | if (is_file($path)) { |
| 39 | 39 | return static::deleteFile($path); |
| 40 | 40 | } |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected $namespace=[ __NAMESPACE__ ]; |
|
| 18 | + protected $namespace = [__NAMESPACE__]; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 包含路径 |
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $includePath=[]; |
|
| 25 | + protected $includePath = []; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * 将JAVA,路径分割转换为PHP分割符 |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function realName(string $name):string |
| 34 | 34 | { |
| 35 | - return str_replace(['.','/'], '\\', $name); |
|
| 35 | + return str_replace(['.', '/'], '\\', $name); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $name |
| 42 | 42 | * @return string|null |
| 43 | 43 | */ |
| 44 | - public static function realPath(string $name):?string |
|
| 44 | + public static function realPath(string $name): ?string |
|
| 45 | 45 | { |
| 46 | 46 | return Path::format($name); |
| 47 | 47 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string $filename |
| 53 | 53 | * @return string|null |
| 54 | 54 | */ |
| 55 | - public function import(string $filename):?string |
|
| 55 | + public function import(string $filename): ?string |
|
| 56 | 56 | { |
| 57 | 57 | if ($filename = static::realPath($filename)) { |
| 58 | 58 | @require_once $filename; |
@@ -68,16 +68,16 @@ discard block |
||
| 68 | 68 | return null; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function addIncludePath(string $path, string $namespace=null) |
|
| 71 | + public function addIncludePath(string $path, string $namespace = null) |
|
| 72 | 72 | { |
| 73 | 73 | if ($path = static::realPath($path)) { |
| 74 | 74 | $namespace = $namespace ?? 0; |
| 75 | 75 | if (array_key_exists($namespace, $this->includePath)) { |
| 76 | 76 | if (!\in_array($path, $this->includePath[$namespace])) { |
| 77 | - $this->includePath[$namespace][]=$path; |
|
| 77 | + $this->includePath[$namespace][] = $path; |
|
| 78 | 78 | } |
| 79 | 79 | } else { |
| 80 | - $this->includePath[$namespace][]=$path; |
|
| 80 | + $this->includePath[$namespace][] = $path; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function setNamespace(string $namespace) |
| 96 | 96 | { |
| 97 | 97 | if (!in_array($namespace, $this->namespace)) { |
| 98 | - $this->namespace[]=$namespace; |
|
| 98 | + $this->namespace[] = $namespace; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | $rpos = \strrpos($name, ':'); |
| 56 | 56 | if ($rpos > 0) { |
| 57 | 57 | $module = substr($name, 0, $rpos); |
| 58 | - $name = \substr($name, $rpos+1); |
|
| 59 | - $moduleFull = $this->getFullName($module); |
|
| 58 | + $name = \substr($name, $rpos + 1); |
|
| 59 | + $moduleFull = $this->getFullName($module); |
|
| 60 | 60 | return [$moduleFull, $name]; |
| 61 | 61 | } |
| 62 | 62 | if ($rpos === 0) { |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (\array_key_exists($version, $this->knownsFullName[$name])) { |
| 78 | 78 | return $this->knownsFullName[$name][$version]; |
| 79 | 79 | } |
| 80 | - return $hasVersion?$name.':'.$version:end($this->knownsFullName[$name]); |
|
| 80 | + return $hasVersion ? $name.':'.$version : end($this->knownsFullName[$name]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | protected function getLikeName(string $name):string |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function add(?string $group = null, string $name, RouteMatcher $router) |
| 48 | 48 | { |
| 49 | - $group = $group ? $this->finder->getFullName($group) : $this->default; |
|
| 49 | + $group = $group ? $this->finder->getFullName($group) : $this->default; |
|
| 50 | 50 | if (\array_key_exists($group, $this->routes)) { |
| 51 | 51 | $this->routes[$group]->add($name, $router); |
| 52 | 52 | } else { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param string $name |
| 61 | 61 | * @return RouteMatcher|null |
| 62 | 62 | */ |
| 63 | - public function find(string $name, ?string $default = null):?RouteMatcher |
|
| 63 | + public function find(string $name, ?string $default = null): ?RouteMatcher |
|
| 64 | 64 | { |
| 65 | 65 | list($group, $name) = $this->finder->info($name, $default ?? $this->default); |
| 66 | 66 | if (\array_key_exists($group, $this->routes)) { |
@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | abstract class ConfigLoader |
| 11 | 11 | { |
| 12 | - public function loadConfig(string $path, array $extra =[]):?array |
|
| 12 | + public function loadConfig(string $path, array $extra = []): ?array |
|
| 13 | 13 | { |
| 14 | - $data=null; |
|
| 14 | + $data = null; |
|
| 15 | 15 | if (!file_exists($path)) { |
| 16 | 16 | $path = static::resolve($path); |
| 17 | 17 | } |
@@ -27,25 +27,25 @@ discard block |
||
| 27 | 27 | return $data; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - protected function loadJson(string $path, array $extra =[]):array |
|
| 30 | + protected function loadJson(string $path, array $extra = []):array |
|
| 31 | 31 | { |
| 32 | 32 | $content = file_get_contents($path); |
| 33 | - $content =$this->parseValue($content, $extra); |
|
| 33 | + $content = $this->parseValue($content, $extra); |
|
| 34 | 34 | $data = json_decode($content, true); |
| 35 | - if (json_last_error()!==JSON_ERROR_NONE) { |
|
| 35 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 36 | 36 | throw new JSONException(json_last_error()); |
| 37 | 37 | } |
| 38 | 38 | return $data; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - protected function loadIni(string $path, array $extra =[]):array |
|
| 41 | + protected function loadIni(string $path, array $extra = []):array |
|
| 42 | 42 | { |
| 43 | 43 | $content = file_get_contents($path); |
| 44 | - $content =$this->parseValue($content, $extra); |
|
| 44 | + $content = $this->parseValue($content, $extra); |
|
| 45 | 45 | return \parse_ini_string($content, true) ?: []; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - protected function loadYaml(string $path, array $extra =[]):array |
|
| 48 | + protected function loadYaml(string $path, array $extra = []):array |
|
| 49 | 49 | { |
| 50 | 50 | if (function_exists('yaml_parse')) { |
| 51 | 51 | $name = 'yaml_parse'; |
@@ -55,25 +55,25 @@ discard block |
||
| 55 | 55 | throw new YamlException("parse yaml config error : missing yaml extension or spyc", 1); |
| 56 | 56 | } |
| 57 | 57 | $content = file_get_contents($path); |
| 58 | - $content =$this->parseValue($content, $extra); |
|
| 58 | + $content = $this->parseValue($content, $extra); |
|
| 59 | 59 | return \call_user_func_array($name, [$content]); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - abstract public function parseValue(string $content, array $extra =[]):string; |
|
| 62 | + abstract public function parseValue(string $content, array $extra = []):string; |
|
| 63 | 63 | |
| 64 | - public static function resolve(string $path):?string |
|
| 64 | + public static function resolve(string $path): ?string |
|
| 65 | 65 | { |
| 66 | 66 | if (file_exists($path)) { |
| 67 | 67 | return $path; |
| 68 | 68 | } |
| 69 | 69 | $basepath = pathinfo($path, PATHINFO_FILENAME); |
| 70 | - if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
| 70 | + if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
| 71 | 71 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
| 72 | 72 | return $conf; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | - foreach (['.json','.php','.ini'] as $ext) { |
|
| 76 | - if (file_exists($conf=$basepath.$ext)) { |
|
| 75 | + foreach (['.json', '.php', '.ini'] as $ext) { |
|
| 76 | + if (file_exists($conf = $basepath.$ext)) { |
|
| 77 | 77 | return $conf; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $path = $source; |
| 30 | 30 | if (Path::isRelativePath($source)) { |
| 31 | - $path = $relative.'/'.$path; |
|
| 31 | + $path = $relative.'/'.$path; |
|
| 32 | 32 | } |
| 33 | 33 | return Path::toAbsolutePath($path); |
| 34 | 34 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param string $path |
| 54 | 54 | * @return string|null |
| 55 | 55 | */ |
| 56 | - public function getResourcePath(string $path):?string |
|
| 56 | + public function getResourcePath(string $path): ?string |
|
| 57 | 57 | { |
| 58 | 58 | foreach ($this->resource as $root) { |
| 59 | 59 | $target = $root.'/'.$path; |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | * @param string $path |
| 71 | 71 | * @return string|null |
| 72 | 72 | */ |
| 73 | - public function getConfigResourcePath(string $path):?string |
|
| 73 | + public function getConfigResourcePath(string $path): ?string |
|
| 74 | 74 | { |
| 75 | 75 | foreach ($this->resource as $root) { |
| 76 | - if ( $target = Config::resolve($root.'/'.$path)) { |
|
| 76 | + if ($target = Config::resolve($root.'/'.$path)) { |
|
| 77 | 77 | return $target; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use nebula\NebulaApplication; |
| 4 | 4 | use nebula\application\Loader; |
| 5 | 5 | |
| 6 | -require_once __DIR__ .'/loader.php'; |
|
| 6 | +require_once __DIR__.'/loader.php'; |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | $loader = new Loader; |
| 13 | 13 | $loader->register(); |
| 14 | -$loader->addIncludePath(NEBULA_SYSTEM .'/src', 'nebula'); |
|
| 14 | +$loader->addIncludePath(NEBULA_SYSTEM.'/src', 'nebula'); |
|
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | $nebula = NebulaApplication::configuration(constant('NEBULA_APP')); |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * @throws FileLoggerException |
| 47 | 47 | * @param array $config |
| 48 | 48 | */ |
| 49 | - public function __construct(array $config=[]) |
|
| 49 | + public function __construct(array $config = []) |
|
| 50 | 50 | { |
| 51 | 51 | $this->applyConfig($config); |
| 52 | 52 | $temp = tmpfile(); |
| 53 | 53 | if ($temp === false) { |
| 54 | - $this->tempname = $this->getConfig('save-path').'/log-'. microtime(true).'.tmp'; |
|
| 54 | + $this->tempname = $this->getConfig('save-path').'/log-'.microtime(true).'.tmp'; |
|
| 55 | 55 | $temp = fopen($this->tempname, 'w+'); |
| 56 | 56 | } |
| 57 | 57 | if ($temp !== false) { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file')); |
| 61 | 61 | } |
| 62 | 62 | $this->latest = $this->getConfig('save-path').'/'.$this->getConfig('file-name'); |
| 63 | - \register_shutdown_function([$this,'save']); |
|
| 63 | + \register_shutdown_function([$this, 'save']); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function getDefaultConfig():array |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | protected function packLogFile() |
| 80 | 80 | { |
| 81 | - $logFile= $this->latest; |
|
| 82 | - $path=preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip'); |
|
| 81 | + $logFile = $this->latest; |
|
| 82 | + $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path').'/'.date('Y-m-d').'.zip'); |
|
| 83 | 83 | $zip = new ZipArchive; |
| 84 | 84 | $res = $zip->open($path, ZipArchive::CREATE); |
| 85 | 85 | if ($res === true) { |
| 86 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
| 86 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
| 87 | 87 | array_push($this->removeFiles, $logFile); |
| 88 | 88 | } |
| 89 | 89 | if (\is_dir($this->getConfig('save-pack-path'))) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $zip->close(); |
| 98 | 98 | } else { |
| 99 | 99 | if (is_file($logFile) && file_exists($logFile)) { |
| 100 | - rename($logFile, $this->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
| 100 | + rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | protected function checkSize():bool |
| 111 | 111 | { |
| 112 | - $logFile= $this->latest; |
|
| 112 | + $logFile = $this->latest; |
|
| 113 | 113 | if (file_exists($logFile)) { |
| 114 | 114 | if (filesize($logFile) > $this->getConfig('max-file-size')) { |
| 115 | 115 | return true; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function log($level, string $message, array $context = []) |
| 123 | 123 | { |
| 124 | - if (LogLevel::compare($level, $this->getConfig('log-level')) >=0) { |
|
| 124 | + if (LogLevel::compare($level, $this->getConfig('log-level')) >= 0) { |
|
| 125 | 125 | $replace = []; |
| 126 | 126 | $message = $this->interpolate($message, $context); |
| 127 | 127 | $replace['%level%'] = $level; |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | protected function rollLatest() |
| 135 | 135 | { |
| 136 | 136 | if (isset($this->latest)) { |
| 137 | - $size=ftell($this->temp); |
|
| 137 | + $size = ftell($this->temp); |
|
| 138 | 138 | fseek($this->temp, 0); |
| 139 | 139 | if ($size > 0) { |
| 140 | - $body=fread($this->temp, $size); |
|
| 140 | + $body = fread($this->temp, $size); |
|
| 141 | 141 | file_put_contents($this->latest, $body, FILE_APPEND); |
| 142 | 142 | } |
| 143 | 143 | fclose($this->temp); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $replace = []; |
| 171 | 171 | foreach ($context as $key => $val) { |
| 172 | - $replace['{' . $key . '}'] = $val; |
|
| 172 | + $replace['{'.$key.'}'] = $val; |
|
| 173 | 173 | } |
| 174 | 174 | return strtr($message, $replace); |
| 175 | 175 | } |
@@ -20,9 +20,9 @@ |
||
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -require_once NEBULA_SYSTEM .'/src/component/loader/Path.php'; |
|
| 24 | -require_once NEBULA_SYSTEM .'/src/component/loader/PathTrait.php'; |
|
| 25 | -require_once NEBULA_SYSTEM .'/src/component/loader/PathInterface.php'; |
|
| 26 | -require_once NEBULA_SYSTEM .'/src/component/loader/IncludeManager.php'; |
|
| 27 | -require_once NEBULA_SYSTEM .'/src/component/loader/Loader.php'; |
|
| 28 | -require_once NEBULA_SYSTEM .'/src/application/Loader.php'; |
|
| 23 | +require_once NEBULA_SYSTEM.'/src/component/loader/Path.php'; |
|
| 24 | +require_once NEBULA_SYSTEM.'/src/component/loader/PathTrait.php'; |
|
| 25 | +require_once NEBULA_SYSTEM.'/src/component/loader/PathInterface.php'; |
|
| 26 | +require_once NEBULA_SYSTEM.'/src/component/loader/IncludeManager.php'; |
|
| 27 | +require_once NEBULA_SYSTEM.'/src/component/loader/Loader.php'; |
|
| 28 | +require_once NEBULA_SYSTEM.'/src/application/Loader.php'; |
|