@@ -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); |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | protected $matcher; |
41 | 41 | |
42 | 42 | |
43 | - public function __construct(array $methods, string $uri, array $attribute=[]) |
|
43 | + public function __construct(array $methods, string $uri, array $attribute = []) |
|
44 | 44 | { |
45 | - array_walk($methods, function ($value) { |
|
45 | + array_walk($methods, function($value) { |
|
46 | 46 | return strtoupper($value); |
47 | 47 | }); |
48 | 48 | $this->methods = $methods; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param RequestInterface $request |
140 | 140 | * @return array|null |
141 | 141 | */ |
142 | - public function match(RequestInterface $request):?array { |
|
142 | + public function match(RequestInterface $request): ?array { |
|
143 | 143 | if (\in_array($request->getMethod(), $this->methods)) { |
144 | 144 | if ($parameter = $this->matcher->match($request->getUrl())) { |
145 | 145 | return $this->matcher->buildParamter($parameter); |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param boolean $ignoreCase |
47 | 47 | * @return array|null |
48 | 48 | */ |
49 | - public function match(string $url, bool $ignoreCase = true):?array |
|
49 | + public function match(string $url, bool $ignoreCase = true): ?array |
|
50 | 50 | { |
51 | - $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':''); |
|
51 | + $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : ''); |
|
52 | 52 | $parameter = []; |
53 | 53 | if (preg_match($match, $url, $parameter, PREG_UNMATCHED_AS_NULL) > 0) { |
54 | 54 | return array_slice($parameter, 1); |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | } else { |
73 | 73 | $value = $parameter->unpackValue($match); |
74 | 74 | } |
75 | - $parameters[$parameter->getIndexName()] = $value; |
|
75 | + $parameters[$parameter->getIndexName()] = $value; |
|
76 | 76 | } |
77 | 77 | return $parameters; |
78 | 78 | } |
79 | 79 | |
80 | - public function getParameter(string $name):?Parameter |
|
80 | + public function getParameter(string $name): ?Parameter |
|
81 | 81 | { |
82 | 82 | foreach ($this->parameter as $parameter) { |
83 | 83 | if ($parameter->getIndexName() === $name) { |
@@ -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 | } |