@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | public static function formatSeparator(string $path):string |
| 11 | 11 | { |
| 12 | - return str_replace(['\\','/'], DIRECTORY_SEPARATOR, $path); |
|
| 12 | + return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public static function toAbsolutePath(string $path, string $separator = DIRECTORY_SEPARATOR):string{ |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $subpath = substr($subpath, 1); |
| 31 | 31 | } else { |
| 32 | 32 | if (strpos($subpath, ':/') === false) { |
| 33 | - $subpath=str_replace(['/', '\\'], '/', getcwd()).'/'.$subpath; |
|
| 33 | + $subpath = str_replace(['/', '\\'], '/', getcwd()).'/'.$subpath; |
|
| 34 | 34 | } |
| 35 | 35 | list($root, $subpath) = explode(':/', $subpath, 2); |
| 36 | 36 | $root .= ':'.DIRECTORY_SEPARATOR; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } elseif ($name === '.') { |
| 49 | 49 | continue; |
| 50 | 50 | } elseif (strlen($name)) { |
| 51 | - $absulotePaths[]=$name; |
|
| 51 | + $absulotePaths[] = $name; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | return implode($separator, $absulotePaths); |
@@ -57,20 +57,20 @@ discard block |
||
| 57 | 57 | protected static function parsePathSchemeSubpath(string $path):array |
| 58 | 58 | { |
| 59 | 59 | if (static::getHomePath() !== null && strpos($path, '~') === 0) { |
| 60 | - $scheme =''; |
|
| 61 | - $subpath = static::getHomePath() .DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 60 | + $scheme = ''; |
|
| 61 | + $subpath = static::getHomePath().DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 62 | 62 | } elseif (strpos($path, '://') !== false) { |
| 63 | 63 | list($scheme, $subpath) = explode('://', $path, 2); |
| 64 | - $scheme.='://'; |
|
| 64 | + $scheme .= '://'; |
|
| 65 | 65 | } else { |
| 66 | - $scheme =''; |
|
| 66 | + $scheme = ''; |
|
| 67 | 67 | $subpath = $path; |
| 68 | 68 | } |
| 69 | 69 | return [$scheme, $subpath]; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
| 73 | - public static function getHomePath():?string { |
|
| 73 | + public static function getHomePath(): ?string { |
|
| 74 | 74 | if (defined('USER_HOME_PATH')) { |
| 75 | 75 | return constant('USER_HOME_PATH'); |
| 76 | 76 | } |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected static $namespace=[ __NAMESPACE__ ]; |
|
| 18 | + protected static $namespace = [__NAMESPACE__]; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 包含路径 |
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected static $includePath=[]; |
|
| 25 | + protected static $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,10 +41,10 @@ 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 | $absulotePath = static::toAbsolutePath($name); |
| 47 | - return file_exists($absulotePath)?$absulotePath:null; |
|
| 47 | + return file_exists($absulotePath) ? $absulotePath : null; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param string $filename |
| 65 | 65 | * @return string|null |
| 66 | 66 | */ |
| 67 | - public static function import(string $filename):?string |
|
| 67 | + public static function import(string $filename): ?string |
|
| 68 | 68 | { |
| 69 | 69 | if ($filename = static::realPath($filename)) { |
| 70 | 70 | @require_once $filename; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param string $className |
| 102 | 102 | * @return string|null |
| 103 | 103 | */ |
| 104 | - public static function getClassPath(string $className):?string |
|
| 104 | + public static function getClassPath(string $className): ?string |
|
| 105 | 105 | { |
| 106 | 106 | // 搜索路径 |
| 107 | 107 | foreach (static::$includePath as $includeNamespace => $includePaths) { |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @param string $className |
| 124 | 124 | * @return string|null |
| 125 | 125 | */ |
| 126 | - protected static function getClassPathByAlias(string $includePath, string $className):?string |
|
| 126 | + protected static function getClassPathByAlias(string $includePath, string $className): ?string |
|
| 127 | 127 | { |
| 128 | - $namepath=static::formatSeparator($className); |
|
| 129 | - $className=static::realName($className); |
|
| 128 | + $namepath = static::formatSeparator($className); |
|
| 129 | + $className = static::realName($className); |
|
| 130 | 130 | foreach (static::$namespace as $namespace) { |
| 131 | 131 | $path = $includePath.DIRECTORY_SEPARATOR.$namespace.DIRECTORY_SEPARATOR.$namepath.'.php'; |
| 132 | 132 | if ($path = static::realPath($path)) { |
@@ -148,16 +148,16 @@ discard block |
||
| 148 | 148 | * @param string $className |
| 149 | 149 | * @return string|null |
| 150 | 150 | */ |
| 151 | - protected static function getClassPathByName(string $includeNamespace, string $includePath, string $className):?string |
|
| 151 | + protected static function getClassPathByName(string $includeNamespace, string $includePath, string $className): ?string |
|
| 152 | 152 | { |
| 153 | 153 | if (is_numeric($includeNamespace)) { |
| 154 | 154 | $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
| 155 | 155 | } else { |
| 156 | 156 | $nl = strlen($includeNamespace); |
| 157 | 157 | if (substr(static::realName($className), 0, $nl) === $includeNamespace) { |
| 158 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 158 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 159 | 159 | } else { |
| 160 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 160 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | if ($path = static::realPath($path)) { |
@@ -166,16 +166,16 @@ discard block |
||
| 166 | 166 | return null; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public static function addIncludePath(string $path, string $namespace=null) |
|
| 169 | + public static function addIncludePath(string $path, string $namespace = null) |
|
| 170 | 170 | { |
| 171 | 171 | if ($path = static::realPath($path)) { |
| 172 | 172 | $namespace = $namespace ?? 0; |
| 173 | 173 | if (array_key_exists($namespace, static::$includePath)) { |
| 174 | 174 | if (!\in_array($path, static::$includePath[$namespace])) { |
| 175 | - static::$includePath[$namespace][]=$path; |
|
| 175 | + static::$includePath[$namespace][] = $path; |
|
| 176 | 176 | } |
| 177 | 177 | } else { |
| 178 | - static::$includePath[$namespace][]=$path; |
|
| 178 | + static::$includePath[$namespace][] = $path; |
|
| 179 | 179 | } |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | public static function setNamespace(string $namespace) |
| 194 | 194 | { |
| 195 | 195 | if (!in_array($namespace, static::$namespace)) { |
| 196 | - static::$namespace[]=$namespace; |
|
| 196 | + static::$namespace[] = $namespace; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | } |