public function do(InternalRequest $ireq)
{
$toMatch = "{$ireq->method}{$ireq->uriPath}";
if (isset($this->cache[$toMatch])) {
list($args, $routeArgs) = $cache = $this->cache[$toMatch];
list($action, $middlewares) = $args;
$ireq->locals["aerys.routeArgs"] = $routeArgs;
// Keep the most recently used entry at the back of the LRU cache
unset($this->cache[$toMatch]);
$this->cache[$toMatch] = $cache;
$ireq->locals["aerys.routed"] = [$isMethodAllowed = true, $action];
if (!empty($middlewares)) {
try {
return yield from responseFilter($middlewares, $ireq);
} catch (FilterException $e) {
end($ireq->badFilterKeys);
unset($ireq->badFilterKeys[key($ireq->badFilterKeys)]);
$ireq->filterErrorFlag = false;
throw $e->getPrevious();
}
}
return;
}
$match = $this->routeDispatcher->dispatch($ireq->method, $ireq->uriPath);
switch ($match[0]) {
case Dispatcher::FOUND:
list(, $args, $routeArgs) = $match;
list($action, $middlewares) = $args;
$ireq->locals["aerys.routeArgs"] = $routeArgs;
if ($this->maxCacheEntries > 0) {
$this->cacheDispatchResult($toMatch, $routeArgs, $args);
}
$ireq->locals["aerys.routed"] = [$isMethodAllowed = true, $action];
if (!empty($middlewares)) {
try {
return yield from responseFilter($middlewares, $ireq);
} catch (FilterException $e) {
end($ireq->badFilterKeys);
unset($ireq->badFilterKeys[key($ireq->badFilterKeys)]);
$ireq->filterErrorFlag = false;
throw $e->getPrevious();
}
}
break;
case Dispatcher::NOT_FOUND:
// Do nothing; allow actions further down the chain a chance to respond.
// If no other registered host actions respond the server will send a
// 404 automatically anyway.
return;
case Dispatcher::METHOD_NOT_ALLOWED:
$allowedMethods = $match[1];
$ireq->locals["aerys.routed"] = [$isMethodAllowed = false, $allowedMethods];
break;
default:
throw new \UnexpectedValueException("Encountered unexpected Dispatcher code");
}
}