for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\component\route;
use Serializable;
use nebula\component\route\uri\UriMatcher;
/**
* 路由匹配器
*
*/
class RouteMatcher
{
* 匹配的方法
* @var array
protected $methods;
* 匹配的URI
* @var string
protected $uri;
* 属性
protected $attribute;
* Uri匹配器
* @var UriMatcher
protected $matcher;
public function __construct(array $methods, string $uri, array $attribute=[])
array_walk($methods, function ($value) {
return strtoupper($value);
});
$this->methods = $methods;
$this->uri = $uri;
$this->matcher = UriMatcher::build($uri);
$this->attribute = $attribute;
}
* Get 属性
* @return array
public function getAttribute()
return $this->attribute;
* Set 属性
* @param array $attribute 属性
* @return self
public function setAttribute(array $attribute)
return $this;
* Get 匹配的方法
public function getMethods()
return $this->methods;
* Set 匹配的方法
* @param array $methods 匹配的方法
public function setMethods(array $methods)
* Get 匹配的URI
* @return string
public function getUri()
return $this->uri;
* Set 匹配的URI
* @param string $uri 匹配的URI
public function setUri(string $uri)
* Get uri匹配器
* @return UriMatcher
public function getMatcher()
return $this->matcher;
* 匹配请求
* @param RequestInterface $request
* @return array|null
public function match(RequestInterface $request):?array {
if (\in_array($request->getMethod(), $this->methods)) {
if ($parameter = $this->matcher->match($request->getUrl())) {
return $this->matcher->buildParamter($parameter);
return null;