/** * Dispatch the correct set of handlers based on the matching HTTP method and request path * @param string $method * @param string $path * @return mixed */ public function dispatch($method, $path) { $dispatcher = $this->getDispatcher(); $info = $dispatcher->dispatch(strtoupper($method), $path); switch ($info[0]) { case Dispatcher::NOT_FOUND: throw new RouteNotFoundException($method, $path); case Dispatcher::METHOD_NOT_ALLOWED: throw new MethodNotAllowedException($method, $path, $info[1]); } list($_, $handlers, $data) = $info; $context = new Context($method, $path, $data, $handlers); return $context->handleNext(); }