/** * Dispatch an action based on the request passed. * @param Request $request * @param Response $response * @return type */ public function dispatch(Request $request, Response $response = null) { // FB::group("[".__METHOD__."] dispatch: $request->action"); $this->route($request); if ($response == null) { $response = new Response(); } // register request and response here and at plugs $this->setRequest($request); $this->setResponse($response); do { $request->setDispatched(true); $this->preDispatch($request); /** * Skip requested action if preDispatch() has reset it */ if (!$this->getRequest()->isDispatched()) { continue; } fb($request, __METHOD__); fb($response, __METHOD__); try { $controller = $this->getController($request, $response); $controller->dispatch($request, $response); } catch (Exception $exc) { // FB::groupEnd(); // FB::groupEnd(); fb($exc); fb($controller); $o = DataRecord::createErrorOutSt(); $o['data'] = $exc; $response->loadData($exc); } /** * zend post dispatch with the plugin broker. */ $this->postDispatch($request); } while (!$request->isDispatched()); if ($this->returnResponse()) { return $this->getResponse(); } $this->getResponse()->sendResponse(); // FB::groupEnd(); }