lithium\net\http\Route::_regex()
Generates a sub-expression capture group for a route regex, using an optional user-supplied matching pattern.
Parameters
-
string
$regexAn optional user-supplied match pattern. If a route is defined like
"/{:id:\d+}", then the value will be"\d+". -
string
$paramThe parameter name which the capture group is assigned to, i.e.
'controller','id'or'args'. -
string
$tokenThe full token representing a matched element in a route template, i.e.
'/{:action}','/{:path:js|css}', or'.{:type}'. -
string
$prefixThe prefix character that separates the parameter from the other elements of the route. Usually
'.'or'/'.
Returns
stringReturns the full route template, with the value of $token replaced with a
generated regex capture group.
Source
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);
}