public static parse ( object $request ) : array | ||
$request | object | A request object containing URL and environment data. |
return | array | Returns an array of parameters specifying how the given request should be routed. The keys returned depend on the `Route` object that was matched, but typically include `'controller'` and `'action'` keys. |
public static function parse($request)
{
foreach (static::$_configurations as $name => $value) {
$original = $request->params;
$name = is_int($name) ? false : $name;
if (!($url = static::_parseScope($name, $request))) {
continue;
}
foreach (static::$_configurations[$name] as $route) {
if (!($match = $route->parse($request, compact('url')))) {
continue;
}
$request = $match;
if ($route->canContinue() && isset($request->params['args'])) {
$url = '/' . join('/', $request->params['args']);
unset($request->params['args']);
continue;
}
static::attach($name, null, isset($request->params) ? $request->params : array());
static::scope($name);
return $request;
}
$request->params = $original;
}
}
/** * Compare $url with $mask. Returns true if there is a match ! * * @param mixed $url String, array or Request : url to test * @param array $mask Mask, in a Request::$params form * @return bool Yep/nope ? */ public static function match($url, array $mask) { // Multiple $url types if ($url instanceof Request) { $test = Router::parse($url); } elseif (is_string($url)) { $request = new Request(); $request->url = $url; $test = Router::parse($request); } else { $test = $url; } foreach ($mask as $key => $value) { if (!isset($test[$key])) { return false; } if (is_array($value) && !static::match($mask[$key], $test[$key])) { return false; } if (is_string($value) && strtolower($value) !== strtolower($test[$key])) { return false; } } return true; }