/** * Render the decorators * * This method will also add the 'decorator' filter to the view and add following default parameters * * - component: The name of the component being dispatched * - language: The language of the response * - status: The status code of the response * * @param DispatcherContext $context The active command context * @return void */ protected function _beforeSend(DispatcherContext $context) { $response = $context->getResponse(); if (!$response->isDownloadable()) { foreach ($this->getDecorators() as $decorator) { //Get the decorator $config = array('response' => array('content' => $response->getContent())); $controller = $this->getObject($decorator, $config); if (!$controller instanceof ControllerViewable) { throw new \UnexpectedValueException('Decorator ' . get_class($controller) . ' does not implement ControllerViewable'); } //Set the view $parameters = array('language' => $this->getLanguage()); if ($response->isError()) { $parameters['status'] = $response->getStatusCode(); } else { $parameters['component'] = $this->getController()->getIdentifier()->package; } $controller->getView()->setParameters($parameters)->getTemplate()->addFilter('decorator'); //Set the response $response->setContent($controller->render()); } } }
/** * Challenge the response * * @param DispatcherContext $context A dispatcher context object * @return bool Returns TRUE if the response could be signed, FALSE otherwise. */ public function challengeResponse(DispatcherContext $context) { $response = $context->getResponse(); //The response MUST include a WWW-Authenticate header field. if ($response->getStatusCode() == HttpResponse::UNAUTHORIZED) { $response->headers->set('Www-Authenticate', ucfirst($this->getScheme()) . ' realm="' . $this->getRealm() . '"', false); } }