/** * @param \Zend\Stdlib\ResponseInterface $r * @param \Zend_Controller_Response_Abstract $response */ public function renderIntoResponse(Response $r, \Zend_Controller_Response_Abstract $response) { // render ZF1 response into ZF2 response if ($response->isException() && $response->renderExceptions()) { $exceptions = ''; foreach ($response->getException() as $e) { $exceptions .= $e . "\n"; } $body = $exceptions; } else { $body = $response->getBody(); } $r->setContent($body); if ($r instanceof HttpResponse) { $r->setStatusCode($response->getHttpResponseCode()); $r->setHeaders($this->getHeadersFromResponse($response)); $type = $r->getHeaders()->get('Content-Type'); if (!$type) { $r->getHeaders()->addHeaderLine('Content-Type', 'text/html'); } } }
/** * Set the asset on the response, including headers and content. * * @param ResponseInterface $response * @return ResponseInterface * @throws Exception\RuntimeException */ public function setAssetOnResponse(ResponseInterface $response) { if (!$this->asset instanceof AssetInterface) { throw new Exception\RuntimeException('Unable to set asset on response. Request has not been resolved to an asset.'); } // @todo: Create Asset wrapper for mimetypes if (empty($this->asset->mimetype)) { throw new Exception\RuntimeException('Expected property "mimetype" on asset.'); } $this->getAssetFilterManager()->setFilters($this->path, $this->asset); $this->asset = $this->getAssetCacheManager()->setCache($this->path, $this->asset); $mimeType = $this->asset->mimetype; $assetContents = $this->asset->dump(); // @codeCoverageIgnoreStart if (function_exists('mb_strlen')) { $contentLength = mb_strlen($assetContents, '8bit'); } else { $contentLength = strlen($assetContents); } // @codeCoverageIgnoreEnd if (!empty($this->config['clear_output_buffer']) && $this->config['clear_output_buffer']) { // Only clean the output buffer if it's turned on and something // has been buffered. if (ob_get_length() > 0) { ob_clean(); } } $response->getHeaders()->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Type', $mimeType)->addHeaderLine('Content-Length', $contentLength); $response->setContent($assetContents); $this->assetSetOnResponse = true; return $response; }