/** * Dispatch the request to the action of the controller * @return null */ protected function dispatch() { if (!$this->request) { // there is no request to start with, so we just return the // appropriate HTTP response status code $this->response->setStatusCode(Response::STATUS_CODE_NOT_IMPLEMENTED); return; } $dispatcher = $this->getDispatcher(); // request chaining while ($this->request) { $this->eventManager->triggerEvent(self::EVENT_PRE_DISPATCH, $this); if (!$this->request) { continue; } try { $chainedRequest = $dispatcher->dispatch($this->request, $this->response); if ($chainedRequest && !$chainedRequest instanceof Request) { throw new ZiboException('Action returned a invalid value, return nothing or a new zibo\\core\\Request object for request chaining.'); } $this->setRequest($chainedRequest); } catch (Exception $exception) { $this->eventManager->triggerEvent(self::EVENT_ERROR, $exception); $this->setRequest(null); } $this->eventManager->triggerEvent(self::EVENT_POST_DISPATCH, $this); } }