private function matchRoutes(Request $request, Response $response, $next)
{
$badMethod = false;
foreach ($this->routes as $route) {
if (!$route->isParsed()) {
$route->parse();
}
if (preg_match('#' . $route->parsed . '$#', $request->httpRequest->getPath(), $array)) {
if ($route->method != strtoupper($request->httpRequest->getMethod())) {
$badMethod = true;
continue;
}
$methodArgs = array();
foreach ($array as $name => $value) {
if (!is_int($name)) {
$methodArgs[$name] = $value;
}
}
if (count($methodArgs) > 0) {
$request->setData($methodArgs);
}
$route->run($request, $response, $next);
return;
}
}
if ($badMethod) {
$this->emit('MethodNotAllowed', array($request, $response, $next));
return;
}
$this->emit('NotFound', array($request, $response, $next));
}