public function getEventForRequest(RequestInterface $request) { $requestedRoute = $request->getUrl()->getPath(); $requestedMethod = $request->getMethod(); $routeInfo = $this->dispatcher->dispatch($requestedMethod, $requestedRoute); switch ($routeInfo[0]) { case Dispatcher::NOT_FOUND: throw new NotFoundException('Route \'' . $requestedRoute . '\' with method \'' . $requestedMethod . '\' not found.'); break; case Dispatcher::METHOD_NOT_ALLOWED: //$allowedMethods = $routeInfo[1]; throw new Exception('Method not allowed', StatusCode::METHOD_NOT_ALLOWED); break; case Dispatcher::FOUND: /** @var string $eventClass */ $eventClass = $routeInfo[1]; /** @var RouteFoundEvent $event */ $event = new $eventClass(); /** @var string[] $vars */ $vars = $routeInfo[2]; $request->getRouteParameterCollection()->setAll($vars); $event->setRequest($request); return $event; default: throw new Exception('Error in FastRoute!'); } }