129 $this->pattern = str_replace(
')',
')?', (
string)
$pattern);
181 $this->router->cacheNamedRoute($this->
name, $this);
197 $args = func_get_args();
198 $this->methods = $args;
214 $args = func_get_args();
215 $this->methods = array_merge($this->methods, $args);
223 $args = func_get_args();
224 $this->methods = array_merge($this->methods, $args);
233 return in_array($method, $this->methods);
280 $this->middleware = array_merge($this->middleware,
$middleware);
282 throw new InvalidArgumentException(
'Route middleware must be callable or an array of callables');
300 preg_match_all(
'@:([\w]+)@', $this->pattern, $paramNames, PREG_PATTERN_ORDER);
301 $paramNames = $paramNames[0];
304 $patternAsRegex = preg_replace_callback(
'@:[\w]+@', array($this,
'convertPatternToRegex'), $this->pattern);
305 if ( substr($this->pattern, -1) ===
'/' ) {
306 $patternAsRegex = $patternAsRegex .
'?';
308 $patternAsRegex =
'@^' . $patternAsRegex .
'$@';
311 if ( preg_match($patternAsRegex, $resourceUri, $paramValues) ) {
312 array_shift($paramValues);
313 foreach ( $paramNames as $index => $value ) {
314 $val = substr($value, 1);
315 if ( isset($paramValues[$val]) ) {
316 $this->params[$val] = urldecode($paramValues[$val]);
331 $key = str_replace(
':',
'', $matches[0]);
332 if ( array_key_exists($key, $this->
conditions) ) {
333 return '(?P<' . $key .
'>' . $this->
conditions[$key] .
')';
335 return '(?P<' . $key .
'>[a-zA-Z0-9_\-\.\!\~\*\\\'\(\)\:\@\&\=\$\+,%]+)';
381 if ( substr($this->pattern, -1) ===
'/' && substr($this->router->getRequest()->getResourceUri(), -1) !==
'/' ) {
385 foreach ( $this->middleware as $mw ) {
386 if ( is_callable($mw) ) {
392 call_user_func_array($this->callable, array_values($this->params));