@@ -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 | } |
@@ -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 | } |