@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } else { |
| 153 | 153 | $indexFile = substr($this->getEntranceFile(), strlen($this->getDocumentRoot())); |
| 154 | 154 | } |
| 155 | - return $this->indexFile = str_replace('\\', '/' ,$indexFile); |
|
| 155 | + return $this->indexFile = str_replace('\\', '/', $indexFile); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -165,26 +165,26 @@ discard block |
||
| 165 | 165 | { |
| 166 | 166 | $url = $this->uri; |
| 167 | 167 | |
| 168 | - $queryString=''; |
|
| 168 | + $queryString = ''; |
|
| 169 | 169 | // for /?/xx |
| 170 | 170 | if (\strpos($url, '/?/') === 0) { |
| 171 | 171 | $url = substr($url, 2); |
| 172 | 172 | } |
| 173 | 173 | $indexFile = $this->getIndexFile(); |
| 174 | - if (\strpos($url, $indexFile) ===0) { |
|
| 174 | + if (\strpos($url, $indexFile) === 0) { |
|
| 175 | 175 | // for /index.php/ |
| 176 | - $url = \substr($url, strlen($indexFile));// for /index.php?/ |
|
| 176 | + $url = \substr($url, strlen($indexFile)); // for /index.php?/ |
|
| 177 | 177 | if (\strpos($url, '?/') === 0) { |
| 178 | 178 | $url = ltrim($url, '?'); |
| 179 | 179 | } |
| 180 | 180 | // for /index.php |
| 181 | - elseif (\strpos($url, '/')!== 0) { |
|
| 181 | + elseif (\strpos($url, '/') !== 0) { |
|
| 182 | 182 | $url = '/'.$url; |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | $queryStart = \strpos($url, '?'); |
| 186 | 186 | if ($queryStart !== false) { |
| 187 | - $queryString = \substr($url, $queryStart+1); |
|
| 187 | + $queryString = \substr($url, $queryStart + 1); |
|
| 188 | 188 | $url = \substr($url, 0, $queryStart); |
| 189 | 189 | } |
| 190 | 190 | $this->url = $url; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | parse_str($queryString, $this->queryParameter); |
| 193 | 193 | } |
| 194 | 194 | if ($applyServer) { |
| 195 | - $_SERVER['PATH_INFO'] = $this->url; |
|
| 195 | + $_SERVER['PATH_INFO'] = $this->url; |
|
| 196 | 196 | $_SERVER['SCRIPT_NAME'] = $this->getIndexFile(); |
| 197 | 197 | $_SERVER['PHP_SELF'] = $this->getIndexFile(); |
| 198 | 198 | $_GET = $this->queryParameter; |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | $serverBasicUri = $this->getServerUri(); |
| 212 | 212 | $indexFile = $this->getIndexFile(); |
| 213 | - $isWindows = DIRECTORY_SEPARATOR === '\\'; |
|
| 214 | - $isRoot= in_array(substr($indexFile, 1), static::getDefaultIndexs()); |
|
| 213 | + $isWindows = DIRECTORY_SEPARATOR === '\\'; |
|
| 214 | + $isRoot = in_array(substr($indexFile, 1), static::getDefaultIndexs()); |
|
| 215 | 215 | if ($this->enabledRewrite && $isRoot) { |
| 216 | 216 | if ($isWindows && !$this->enabledBeautifyUrl) { |
| 217 | 217 | return $this->basicUri = $serverBasicUri.'/?/'; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @return array|null |
| 46 | 46 | */ |
| 47 | - public function json():?array; |
|
| 47 | + public function json(): ?array; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * 获取GET参数 |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param mixed $default |
| 54 | 54 | * @return mixed |
| 55 | 55 | */ |
| 56 | - public function get(?string $name=null, $default =null); |
|
| 56 | + public function get(?string $name = null, $default = null); |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * 获取POST请求的值 |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param mixed $default |
| 63 | 63 | * @return mixed 获取的值 |
| 64 | 64 | */ |
| 65 | - public static function post(?string $name=null, $default=null); |
|
| 65 | + public static function post(?string $name = null, $default = null); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * 获取HTTP输入 |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param string|null $name |
| 86 | 86 | * @return boolean |
| 87 | 87 | */ |
| 88 | - public function hasGet(?string $name=null); |
|
| 88 | + public function hasGet(?string $name = null); |
|
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | 91 | * 判断是否有JSON数据请求 |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return boolean |
| 101 | 101 | */ |
| 102 | - public function hasPost(?string $name=null); |
|
| 102 | + public function hasPost(?string $name = null); |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * 获取参数 |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param mixed $default |
| 116 | 116 | * @return mixed |
| 117 | 117 | */ |
| 118 | - public function getHeader(string $name, $default =null); |
|
| 118 | + public function getHeader(string $name, $default = null); |
|
| 119 | 119 | |
| 120 | 120 | // Uri |
| 121 | 121 | /** |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | /** |
| 8 | 8 | * HTTP请求文件 |
| 9 | 9 | */ |
| 10 | -class UploadedFile extends File { |
|
| 10 | +class UploadedFile extends File { |
|
| 11 | 11 | |
| 12 | 12 | private $originalName; |
| 13 | 13 | private $mimeType; |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | /** |
| 6 | 6 | * HTTP请求文件 |
| 7 | 7 | */ |
| 8 | -class File extends \SplFileInfo { |
|
| 8 | +class File extends \SplFileInfo { |
|
| 9 | 9 | /** |
| 10 | 10 | * 创建文件 |
| 11 | 11 | * |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @var array |
| 29 | 29 | */ |
| 30 | - protected static $headers =[ |
|
| 30 | + protected static $headers = [ |
|
| 31 | 31 | 'content-type' => ContentTypeItem::class, |
| 32 | 32 | ]; |
| 33 | 33 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ($value instanceof HeaderItem) { |
| 70 | 70 | $header = $value; |
| 71 | 71 | } elseif (array_key_exists($name, static::$headers)) { |
| 72 | - $class =static::$headers[$name]; |
|
| 72 | + $class = static::$headers[$name]; |
|
| 73 | 73 | $header = new $class($name, $value); |
| 74 | 74 | } else { |
| 75 | 75 | $header = new HeaderItem($name, $value); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param mixed $default |
| 67 | 67 | * @return mixed |
| 68 | 68 | */ |
| 69 | - public function getHeader(string $name, $default =null) |
|
| 69 | + public function getHeader(string $name, $default = null) |
|
| 70 | 70 | { |
| 71 | 71 | if (array_key_exists(strtolower($name), $this->headers)) { |
| 72 | 72 | return $this->headers[$name]; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function ip() |
| 94 | 94 | { |
| 95 | - static $ipFrom = ['HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR']; |
|
| 95 | + static $ipFrom = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR']; |
|
| 96 | 96 | foreach ($ipFrom as $key) { |
| 97 | 97 | if (array_key_exists($key, $_SERVER)) { |
| 98 | 98 | foreach (explode(',', $_SERVER[$key]) as $ip) { |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | $method = strtoupper($server['REQUEST_METHOD'] ?? 'GET'); |
| 123 | 123 | $uri = $server['REQUEST_Uri']??'/'; |
| 124 | - $headers = HeaderItem::buildFromServer($server ?: $_SERVER); |
|
| 125 | - $request = new Request($method, $uri, $headers); |
|
| 124 | + $headers = HeaderItem::buildFromServer($server ?: $_SERVER); |
|
| 125 | + $request = new Request($method, $uri, $headers); |
|
| 126 | 126 | $request->setDocumentRoot($server['DOCUMENT_ROOT']); |
| 127 | 127 | if ($simulate && $server !== null) { |
| 128 | 128 | $request->setServer($server); |
@@ -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,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 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param string $filename |
| 55 | 55 | * @return string|null |
| 56 | 56 | */ |
| 57 | - public function import(string $filename):?string |
|
| 57 | + public function import(string $filename): ?string |
|
| 58 | 58 | { |
| 59 | 59 | if ($filename = static::realPath($filename)) { |
| 60 | 60 | @require_once $filename; |
@@ -70,16 +70,16 @@ discard block |
||
| 70 | 70 | return null; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function addIncludePath(string $path, string $namespace=null) |
|
| 73 | + public function addIncludePath(string $path, string $namespace = null) |
|
| 74 | 74 | { |
| 75 | 75 | if ($path = static::realPath($path)) { |
| 76 | 76 | $namespace = $namespace ?? 0; |
| 77 | 77 | if (array_key_exists($namespace, $this->includePath)) { |
| 78 | 78 | if (!\in_array($path, $this->includePath[$namespace])) { |
| 79 | - $this->includePath[$namespace][]=$path; |
|
| 79 | + $this->includePath[$namespace][] = $path; |
|
| 80 | 80 | } |
| 81 | 81 | } else { |
| 82 | - $this->includePath[$namespace][]=$path; |
|
| 82 | + $this->includePath[$namespace][] = $path; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | public function setNamespace(string $namespace) |
| 98 | 98 | { |
| 99 | 99 | if (!in_array($namespace, $this->namespace)) { |
| 100 | - $this->namespace[]=$namespace; |
|
| 100 | + $this->namespace[] = $namespace; |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $className |
| 57 | 57 | * @return string|null |
| 58 | 58 | */ |
| 59 | - public function getClassPath(string $className):?string |
|
| 59 | + public function getClassPath(string $className): ?string |
|
| 60 | 60 | { |
| 61 | 61 | // 搜索路径 |
| 62 | 62 | foreach ($this->includePath as $includeNamespace => $includePaths) { |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | * @param string $className |
| 79 | 79 | * @return string|null |
| 80 | 80 | */ |
| 81 | - protected function getClassPathByAlias(string $includePath, string $className):?string |
|
| 81 | + protected function getClassPathByAlias(string $includePath, string $className): ?string |
|
| 82 | 82 | { |
| 83 | - $namepath=static::formatSeparator($className); |
|
| 84 | - $className=static::realName($className); |
|
| 83 | + $namepath = static::formatSeparator($className); |
|
| 84 | + $className = static::realName($className); |
|
| 85 | 85 | foreach ($this->namespace as $namespace) { |
| 86 | 86 | $path = $includePath.DIRECTORY_SEPARATOR.$namespace.DIRECTORY_SEPARATOR.$namepath.'.php'; |
| 87 | 87 | if ($path = static::realPath($path)) { |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | * @param string $className |
| 104 | 104 | * @return string|null |
| 105 | 105 | */ |
| 106 | - protected function getClassPathByName(string $includeNamespace, string $includePath, string $className):?string |
|
| 106 | + protected function getClassPathByName(string $includeNamespace, string $includePath, string $className): ?string |
|
| 107 | 107 | { |
| 108 | 108 | if (is_numeric($includeNamespace)) { |
| 109 | 109 | $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
| 110 | 110 | } else { |
| 111 | 111 | $nl = strlen($includeNamespace); |
| 112 | 112 | if (substr(static::realName($className), 0, $nl) === $includeNamespace) { |
| 113 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 113 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 114 | 114 | } else { |
| 115 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 115 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | if ($path = static::realPath($path)) { |
@@ -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 | } |