for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace nebula\route\uri;
/**
* 可执行命令表达式
*
*/
class UriMatcher
{
* 匹配的正则
* @var string
protected $match;
* URI中的参数
* @var RouteMatcher[]
protected $parameter;
public function __construct(string $match, array $parameter)
$this->match = $match;
$this->parameter = $parameter;
}
* 匹配URL
* @param string $url
* @param boolean $ignoreCase
* @return array|null
public function match(string $url, bool $ignoreCase = true):?array
$match = '#^'. $this->match.'$#'. ($ignoreCase?'i':'');
if (preg_match($match, $url, $parameter)) {
array_shift($parameter);
return $parameter;
return null;
* 构建参数
* @param array $matchParameter
* @return array
public function buildParamter(array $matchParameter):array
$parameters = [];
foreach ($this->parameter as $index => $parameter) {
if (isset($matchParameter[$index])) {
$value = $parameter->getValue($matchParameter[$index]);
} else {
$value = $parameter->getDefaultValue();
$parameters[$parameter->getIndexName()] = $value;
return $parameters;
* Get 匹配的正则
* @return string
public function getMatch()
return $this->match;
* Set 匹配的正则
* @param string $match 匹配的正则
* @return self
public function setMatch(string $match)
return $this;