@@ -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 | public static function register() |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | protected static function getClassPathByAlias(string $includePath, string $className):string |
| 98 | 98 | { |
| 99 | - $namepath=static::formatSeparator($className); |
|
| 100 | - $className=static::realName($className); |
|
| 99 | + $namepath = static::formatSeparator($className); |
|
| 100 | + $className = static::realName($className); |
|
| 101 | 101 | foreach (static::$namespace as $namespace) { |
| 102 | 102 | $path = $includePath.DIRECTORY_SEPARATOR.$namespace.DIRECTORY_SEPARATOR.$namepath.'.php'; |
| 103 | 103 | if ($path = static::realPath($path)) { |
@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | } else { |
| 119 | 119 | $nl = strlen($includeNamespace); |
| 120 | 120 | if (substr(static::realName($className), 0, $nl) === $includeNamespace) { |
| 121 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 121 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 122 | 122 | } else { |
| 123 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 123 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | if ($path = static::realPath($path)) { |
@@ -129,16 +129,16 @@ discard block |
||
| 129 | 129 | return nulll; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public static function addIncludePath(string $path, string $namespace=null) |
|
| 132 | + public static function addIncludePath(string $path, string $namespace = null) |
|
| 133 | 133 | { |
| 134 | 134 | if ($path = static::realPath($path)) { |
| 135 | 135 | $namespace = $namespace ?? 0; |
| 136 | 136 | if (array_key_exists($namespace, static::$includePath)) { |
| 137 | 137 | if (!\in_array($path, static::$includePath[$namespace])) { |
| 138 | - static::$includePath[$namespace][]=$path; |
|
| 138 | + static::$includePath[$namespace][] = $path; |
|
| 139 | 139 | } |
| 140 | 140 | } else { |
| 141 | - static::$includePath[$namespace][]=$path; |
|
| 141 | + static::$includePath[$namespace][] = $path; |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | public static function setNamespace(string $namespace) |
| 157 | 157 | { |
| 158 | 158 | if (!in_array($namespace, static::$namespace)) { |
| 159 | - static::$namespace[]=$namespace; |
|
| 159 | + static::$namespace[] = $namespace; |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -11,5 +11,5 @@ |
||
| 11 | 11 | |
| 12 | 12 | public static function toAbsolutePath(string $path, string $separator = DIRECTORY_SEPARATOR):string; |
| 13 | 13 | |
| 14 | - public static function getHomePath():?string; |
|
| 14 | + public static function getHomePath(): ?string; |
|
| 15 | 15 | } |
@@ -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; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } elseif ($name === '.') { |
| 48 | 48 | continue; |
| 49 | 49 | } elseif (strlen($name)) { |
| 50 | - $absulotePaths[]=$name; |
|
| 50 | + $absulotePaths[] = $name; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | return implode($separator, $absulotePaths); |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | protected static function parsePathSchemeSubpath(string $path):array |
| 57 | 57 | { |
| 58 | 58 | if (static::getHomePath() !== null && strpos($path, '~') === 0) { |
| 59 | - $scheme =''; |
|
| 60 | - $subpath = static::getHomePath() .DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 59 | + $scheme = ''; |
|
| 60 | + $subpath = static::getHomePath().DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 61 | 61 | } elseif (strpos($path, '://') !== false) { |
| 62 | 62 | list($scheme, $subpath) = explode('://', $path, 2); |
| 63 | - $scheme.='://'; |
|
| 63 | + $scheme .= '://'; |
|
| 64 | 64 | } else { |
| 65 | - $scheme =''; |
|
| 65 | + $scheme = ''; |
|
| 66 | 66 | $subpath = $path; |
| 67 | 67 | } |
| 68 | 68 | return [$scheme, $subpath]; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - public static function getHomePath():?string { |
|
| 72 | + public static function getHomePath(): ?string { |
|
| 73 | 73 | return null; |
| 74 | 74 | } |
| 75 | 75 | } |