public function route(Request $request) : array { $path = rawurldecode($request->getURIPath()); $route = $this->dispatcher->dispatch($request->getMethod(), $path); switch ($route[0]) { case Dispatcher::NOT_FOUND: throw new RouteNotFoundException('Undefined route: ' . $path, 404); case Dispatcher::METHOD_NOT_ALLOWED: throw new RouteMethodNotAllowedException('Invalid request method for route ' . $path . ': ' . $request->getMethod(), 405); } list(, $routeInfo, $vars) = $route; $target = is_callable($routeInfo) ? $routeInfo($vars, $this->injector, $this->session, $request) : [$this->injector->make($routeInfo['class']), $routeInfo['method']]; return [$target, $vars]; }