protected _regex ( string $regex, string $param, string $token, string $prefix ) : string | ||
$regex | string | An optional user-supplied match pattern. If a route is defined like `"/{:id:\d+}"`, then the value will be `"\d+"`. |
$param | string | The parameter name which the capture group is assigned to, i.e. `'controller'`, `'id'` or `'args'`. |
$token | string | The full token representing a matched element in a route template, i.e. `'/{:action}'`, `'/{:path:js|css}'`, or `'.{:type}'`. |
$prefix | string | The prefix character that separates the parameter from the other elements of the route. Usually `'.'` or `'/'`. |
리턴 | string | Returns the full route template, with the value of `$token` replaced with a generated regex capture group. |
protected function _regex($regex, $param, $token, $prefix)
{
if ($regex) {
$this->_subPatterns[$param] = $regex;
} elseif ($param == 'args') {
$regex = '.*';
} else {
$regex = '[^\\/]+';
}
$req = $param === 'args' || array_key_exists($param, $this->_params) ? '?' : '';
if ($prefix === '/') {
$pattern = "(?:/(?P<{$param}>{$regex}){$req}){$req}";
} elseif ($prefix === '.') {
$pattern = "\\.(?P<{$param}>{$regex}){$req}";
} else {
$pattern = "(?P<{$param}>{$regex}){$req}";
}
return str_replace($token, $pattern, $this->_pattern);
}