/** * Inject the response * * Injects the response with the rendered content, and sets the content * type based on the detection that occurred during renderer selection. * * @param ViewEvent $e */ public function injectResponse(ViewEvent $e) { parent::injectResponse($e); if ($this->renderer->isApiProblem()) { $e->getResponse()->getHeaders()->addHeaderLine('content-type', 'application/api-problem+json'); $e->getResponse()->setStatusCode($this->renderer->getApiProblem()->status); } }
/** * {@inheritDoc} */ public function injectResponse(ViewEvent $e) { // Test this again here to avoid running our extra code for non-API // requests. $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } parent::injectResponse($e); $model = $e->getModel(); $e->getResponse()->setStatusCode($this->getResponseStatusCode($model)); }