| @@ -40,11 +40,11 @@ | ||
| 40 | 40 | $exstr = ''; | 
| 41 | 41 |          foreach ($array as $key => $value) { | 
| 42 | 42 | $line = ''; | 
| 43 | - $current=$arrname."['".addslashes($key)."']"; | |
| 43 | + $current = $arrname."['".addslashes($key)."']"; | |
| 44 | 44 |              if (is_array($value)) { | 
| 45 | 45 | $line .= self::parserArraySub($current, $value); | 
| 46 | 46 |              } else { | 
| 47 | - $line = $current; | |
| 47 | + $line = $current; | |
| 48 | 48 |                  if (is_string($value)) { | 
| 49 | 49 | $line .= "='".addslashes($value).'\';'.PHP_EOL; | 
| 50 | 50 |                  } elseif (is_bool($value)) { | 
| @@ -87,7 +87,7 @@ discard block | ||
| 87 | 87 | * @param mixed $def | 
| 88 | 88 | * @return array 设置后的数组 | 
| 89 | 89 | */ | 
| 90 | - public static function set(array &$array, string $name, $value, $def=null):array | |
| 90 | + public static function set(array &$array, string $name, $value, $def = null):array | |
| 91 | 91 |      { | 
| 92 | 92 |          $path = explode('.', $name); | 
| 93 | 93 | $root = &$array; | 
| @@ -98,7 +98,7 @@ discard block | ||
| 98 | 98 | $array[$key] = []; | 
| 99 | 99 | } | 
| 100 | 100 |              } else { | 
| 101 | - $array=[]; | |
| 101 | + $array = []; | |
| 102 | 102 | } | 
| 103 | 103 | $array = &$array[$key]; | 
| 104 | 104 | } | 
| @@ -121,7 +121,7 @@ discard block | ||
| 121 | 121 | $array[$key] = []; | 
| 122 | 122 | } | 
| 123 | 123 |              } else { | 
| 124 | - $array=[]; | |
| 124 | + $array = []; | |
| 125 | 125 | } | 
| 126 | 126 | $array = &$array[$key]; | 
| 127 | 127 | } | 
| @@ -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); | 
| @@ -23,7 +23,7 @@ discard block | ||
| 23 | 23 | * | 
| 24 | 24 | * @param RouteMatcher[] $collection | 
| 25 | 25 | */ | 
| 26 | - public function __construct(array $collection=[]) | |
| 26 | + public function __construct(array $collection = []) | |
| 27 | 27 |      { | 
| 28 | 28 | $this->merge($collection); | 
| 29 | 29 | } | 
| @@ -34,7 +34,7 @@ discard block | ||
| 34 | 34 | * @param array $collection | 
| 35 | 35 | * @return void | 
| 36 | 36 | */ | 
| 37 | - public function merge(array $collection=[]) | |
| 37 | + public function merge(array $collection = []) | |
| 38 | 38 |      { | 
| 39 | 39 | $this->collection = array_merge($this->collection, $collection); | 
| 40 | 40 | } | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 | * @param string $name | 
| 58 | 58 | * @return RouteMatcher|null | 
| 59 | 59 | */ | 
| 60 | - public function get(string $name):?RouteMatcher | |
| 60 | + public function get(string $name): ?RouteMatcher | |
| 61 | 61 |      { | 
| 62 | 62 | return $this->collection[$name] ?? null; | 
| 63 | 63 | } | 
| @@ -4,7 +4,7 @@ discard block | ||
| 4 | 4 | /** | 
| 5 | 5 | * 匹配参数 | 
| 6 | 6 | */ | 
| 7 | -abstract class Parameter   { | |
| 7 | +abstract class Parameter { | |
| 8 | 8 | |
| 9 | 9 | protected static $name; | 
| 10 | 10 | /** | 
| @@ -25,7 +25,7 @@ discard block | ||
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | 27 |      public static function build(string $indexName, string $extra):Parameter { | 
| 28 | - $parameter = new static($extra); | |
| 28 | + $parameter = new static($extra); | |
| 29 | 29 | $parameter->setIndexName($indexName); | 
| 30 | 30 | return $parameter; | 
| 31 | 31 | } | 
| @@ -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) { | 
| @@ -26,18 +26,18 @@ discard block | ||
| 26 | 26 | // 参数 | 
| 27 | 27 | $parameters = []; | 
| 28 | 28 | // 转义正则 | 
| 29 | -        $url=preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri); | |
| 29 | +        $url = preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri); | |
| 30 | 30 | // 添加忽略 | 
| 31 | -        $url=preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url); | |
| 31 | +        $url = preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url); | |
| 32 | 32 | // 添加 * ? 匹配 | 
| 33 | - $url=str_replace(['\*','\?'], ['[^/]*?','[^/]'], $url); | |
| 33 | + $url = str_replace(['\*', '\?'], ['[^/]*?', '[^/]'], $url); | |
| 34 | 34 | // 编译页面参数 | 
| 35 | -        $url=preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function ($match) use (&$parameters) { | |
| 35 | +        $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function($match) use (&$parameters) { | |
| 36 | 36 | $name = $match[1]; | 
| 37 | 37 | $type = 'string'; | 
| 38 | 38 | $extra = ''; | 
| 39 | 39 |              if (isset($match[2])) { | 
| 40 | -                if (strpos($match[2], '=')!==false) { | |
| 40 | +                if (strpos($match[2], '=') !== false) { | |
| 41 | 41 |                      list($type, $extra) = \explode('=', $match[2]); | 
| 42 | 42 |                  } else { | 
| 43 | 43 | $type = $match[2]; | 
| @@ -56,16 +56,16 @@ discard block | ||
| 56 | 56 | |
| 57 | 57 | public static function buildUri(UriMatcher $matcher, array $parameter, bool $allowQuery = true):string | 
| 58 | 58 |      { | 
| 59 | - $uri = $matcher->getUri(); | |
| 59 | + $uri = $matcher->getUri(); | |
| 60 | 60 | // 拆分参数 | 
| 61 | 61 | list($mapper, $query) = static::analyseParameter($matcher, $parameter); | 
| 62 | 62 | // for * ? | 
| 63 | - $url=\str_replace(['*','?'], ['','-'], $uri); | |
| 63 | + $url = \str_replace(['*', '?'], ['', '-'], $uri); | |
| 64 | 64 | // for ignore value | 
| 65 | -        $url=preg_replace_callback('/\[(.+?)\]/', function ($match) use ($matcher, $parameter, $mapper) { | |
| 65 | +        $url = preg_replace_callback('/\[(.+?)\]/', function($match) use ($matcher, $parameter, $mapper) { | |
| 66 | 66 |              if (preg_match('/\{(\w+).+?\}/', $match[1])) { | 
| 67 | 67 | $count = 0; | 
| 68 | - $subUrl= static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count); | |
| 68 | + $subUrl = static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count); | |
| 69 | 69 |                  if ($count > 0) { | 
| 70 | 70 | return $subUrl; | 
| 71 | 71 | } | 
| @@ -73,7 +73,7 @@ discard block | ||
| 73 | 73 | return ''; | 
| 74 | 74 | }, $url); | 
| 75 | 75 | |
| 76 | - $url= static::replaceParameter($url, $matcher, $parameter, $mapper); | |
| 76 | + $url = static::replaceParameter($url, $matcher, $parameter, $mapper); | |
| 77 | 77 | |
| 78 | 78 |          if (count($query) && $allowQuery) { | 
| 79 | 79 | return $url.'?'.http_build_query($query, 'v', '&', PHP_QUERY_RFC3986); | 
| @@ -97,9 +97,9 @@ discard block | ||
| 97 | 97 | return [$mapper, $query]; | 
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | - protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, ?int &$count=null) | |
| 100 | + protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, ?int &$count = null) | |
| 101 | 101 |      { | 
| 102 | -        return preg_replace_callback('/\{(\w+).+?\}/', function ($match) use ($matcher, $parameter, $mapper) { | |
| 102 | +        return preg_replace_callback('/\{(\w+).+?\}/', function($match) use ($matcher, $parameter, $mapper) { | |
| 103 | 103 |              if (\array_key_exists($match[1], $mapper)) { | 
| 104 | 104 | return $mapper[$match[1]]->packValue($parameter[$match[1]]); | 
| 105 | 105 | } | 
| @@ -40,11 +40,11 @@ | ||
| 40 | 40 |              while (!feof($fp)) { | 
| 41 | 41 | fseek($fp, $offset); | 
| 42 | 42 | $content = fread($fp, $this->bufferSize); | 
| 43 | - $content.=(feof($fp))? "\n":''; | |
| 43 | + $content .= (feof($fp)) ? "\n" : ''; | |
| 44 | 44 | $size = strpos($content, "\n"); | 
| 45 | 45 | $offset += $size; | 
| 46 | 46 |                  if ($content[$size - 1] === "\r") { | 
| 47 | - $content = substr($content, 0, $size -1); | |
| 47 | + $content = substr($content, 0, $size - 1); | |
| 48 | 48 |                  } else { | 
| 49 | 49 | $content = substr($content, 0, $size); | 
| 50 | 50 | } | 
| @@ -53,9 +53,9 @@ | ||
| 53 | 53 | } | 
| 54 | 54 | |
| 55 | 55 | /** | 
| 56 | - * Get 服务器属性 | |
| 57 | - * | |
| 58 | - * @return array | |
| 59 | - */ | |
| 56 | + * Get 服务器属性 | |
| 57 | + * | |
| 58 | + * @return array | |
| 59 | + */ | |
| 60 | 60 | abstract public function getServer(); | 
| 61 | 61 | } |