public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no yaml return; } // Populate response /** @var Http\Response $response */ $response = $e->getResponse(); $response->setContent($result); /** @var Headers $headers */ $headers = $response->getHeaders(); $contentType = sprintf('application/x-yaml; charset=%s', $this->charset); $headers->addHeaderLine('content-type', $contentType); // Add content-transfer-encoding header in charset is multibyte if (in_array(strtoupper($this->charset), $this->multibyteCharsets)) { $headers->addHeaderLine('content-transfer-encoding', 'BINARY'); } }
/** * 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) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } $model = $e->getModel(); $contentType = $this->contentType; $response = $e->getResponse(); if ($this->renderer->isApiProblem()) { $contentType = 'application/api-problem+json'; $statusCode = $this->getStatusCodeFromApiProblem($this->renderer->getApiProblem()); $response->setStatusCode($statusCode); } elseif ($model instanceof RestfulJsonModel && $model->isApiProblem()) { $contentType = 'application/api-problem+json'; $statusCode = $this->getStatusCodeFromApiProblem($model->getPayload()); $response->setStatusCode($statusCode); } elseif ($model instanceof RestfulJsonModel && ($model->isHalCollection() || $model->isHalResource())) { $contentType = 'application/hal+json'; } // Populate response $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $contentType); }
/** * Inject the response with the PDF payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // @todo Potentially throw an exception here since we should *always* get back a result. return; } $response = $e->getResponse(); $response->setContent($result); $response->getHeaders()->addHeaderLine('content-type', 'application/pdf'); /* @var PdfOptions $pdfOptions */ $pdfOptions = $e->getModel()->getPdfOptions(); $fileName = $pdfOptions->getFileName(); if (isset($fileName)) { if (substr($fileName, -4) != '.pdf') { $fileName .= '.pdf'; } $response->getHeaders()->addHeaderLine('Content-Disposition', 'attachment; filename=' . $fileName); } }
/** * 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) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } $model = $e->getModel(); $contentType = $this->contentType; $response = $e->getResponse(); if ($model instanceof ApiProblemModel) { $contentType = 'application/problem+json'; } elseif ($model instanceof HalJsonModel && ($model->isCollection() || $model->isEntity())) { $contentType = 'application/hal+json'; } /** @var Response $response */ $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $contentType); }
/** * Inject the response with the feed payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result) && !$result instanceof Feed) { // We don't have a string, and thus, no feed return; } // If the result is a feed, export it if ($result instanceof Feed) { $result = $result->export($renderer->getFeedType()); } // Get the content-type header based on feed type $feedType = $renderer->getFeedType(); $feedType = 'rss' == $feedType ? 'application/rss+xml' : 'application/atom+xml'; $model = $e->getModel(); $charset = ''; if ($model instanceof Model\FeedModel) { $feed = $model->getFeed(); $charset = '; charset=' . $feed->getEncoding() . ';'; } // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $feedType . $charset); }
/** * @param ViewEvent $ev * @return void */ public function injectResponse(ViewEvent $ev) { if ($ev->getRenderer() === $this->renderer) { $result = $ev->getResult(); $response = $ev->getResponse(); $response->setContent($result); } }
public function response(ViewEvent $event) { $renderer = $event->getRenderer(); if ($renderer instanceof IcalendarRenderer) { $response = $event->getResponse(); $response->getHeaders()->addHeaderLine('Content-type', 'text/calendar; charset=utf-8'); $response->setContent($event->getResult()); } }
/** * Populate the response object from the view * * Populates the content of the response object from the view rendering * results. * * @param ViewEvent $event * @return void */ public function injectResponse(ViewEvent $event) { if ($event->getRenderer() !== $this->renderer) { return; } $result = $event->getResult(); $response = $event->getResponse(); $response->setContent($result); }
public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return false; } $result = $e->getResult(); $response = $e->getResponse(); $response->setContent($result); }
/** * Sets the response based on image returned by the renderer * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $model = $e->getModel(); if ($model instanceof ImageModel) { $result = $e->getResult(); $response = $e->getResponse(); $response->setContent($result); $response->getHeaders()->addHeaderLine('Content-type', $this->getMimeType($model->getFormat())); } }
/** * @param ViewEvent $e */ public function injectResponse(ViewEvent $e) { if (!$this->model instanceof ApiBlueprintModel) { return; } $response = $e->getResponse(); if (!method_exists($response, 'getHeaders')) { return; } $headers = $response->getHeaders(); $headers->addHeaderLine('Content-Type', 'text/vnd.apiblueprint+markdown'); $response->setContent($e->getResult()); }
public function injectResponse(ViewEvent $e) { $model = $e->getModel(); if (!$model instanceof \Stjornvisi\View\Model\IcalModel) { // no JsonModel; do nothing return; } $result = $e->getResult(); // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', 'text/calendar; charset=utf-8'); }
/** * Inject the response with the feed payload and appropriate Content-Type header * * @param ViewEvent $e * @return void * @throws \Zend\Http\Exception\InvalidArgumentException */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } $result = $e->getResult(); /** @var HttpResponse $response */ $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); //$headers->addHeaderLine('Content-length', strlen($result)); $headers->addHeaderLine('content-type', 'text/xml'); }
public function injectResponse(ViewEvent $e) { $model = $e->getModel(); if (!$model instanceof \Stjornvisi\View\Model\CsvModel) { // no JsonModel; do nothing return; } $csv = $model->getData(); $result = $e->getResult(); // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', 'text/csv; charset=utf-8')->addHeaderLine('Content-Disposition', sprintf("attachment; filename=\"%s\"", $csv->getName())); }
/** * 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) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } $model = $e->getModel(); $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $this->getContentTypeFromModel($model)); }
public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no YAML return; } // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', 'text/yaml'); }
/** * 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) { $renderer = $e->getRenderer(); if (!$renderer instanceof ResourceJsonRenderer) { return; } $result = $e->getResult(); if (!is_string($result)) { return; } $model = $e->getModel(); $contentType = $this->contentType; $response = $e->getResponse(); if ($model instanceof ResourceJsonModel && ($model->isCollection() || $model->isResource())) { $contentType = 'application/hal+json'; } // Populate response $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $contentType); }
/** * 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) { $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } $model = $e->getModel(); if (!$model instanceof ProblemModel) { return; } $problem = $model->getApiProblem(); $statusCode = $this->getStatusCodeFromApiProblem($problem); $contentType = 'application/api-problem+json'; // Populate response $response = $e->getResponse(); $response->setStatusCode($statusCode); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('Content-Type', $contentType); }
/** * 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) { $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } $model = $e->getModel(); if (!$model instanceof ApiProblemModel) { // Model is not an ApiProblemModel; we cannot handle it here return; } $problem = $model->getApiProblem(); $statusCode = $this->getStatusCodeFromApiProblem($problem); $contentType = ApiProblem::CONTENT_TYPE; // Populate response $response = $e->getResponse(); $response->setStatusCode($statusCode); $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('Content-Type', $contentType); }
/** * 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) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string return; } $model = $e->getModel(); $contentType = $this->contentType; $response = $e->getResponse(); if ($model instanceof HtmlModel && ($model->isCollection() || $model->isEntity())) { $contentType = 'text/hal+html'; } // Populate response $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $contentType); }
/** * Inject the response with the feed payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no XML return; } $model = $e->getModel(); $contentType = $this->contentType; $response = $e->getResponse(); if ($model instanceof TwilioModel) { $contentType = $model->getContentType(); } // Populate response $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $contentType); }
public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } $result = $e->getResult(); $response = $e->getResponse(); // Set content // If content is empty, check common placeholders to determine if they are // populated, and set the content from them. /*if (empty($result)) { $placeholders = $renderer->plugin('placeholder'); $registry = $placeholders->getRegistry(); foreach ($this->contentPlaceholders as $placeholder) { if ($registry->containerExists($placeholder)) { $result = (string) $registry->getContainer($placeholder); break; } } }*/ $response->setContent($result); }
/** * Inject the response with the JSON payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); if ($this->renderer->hasJsonpCallback()) { $headers->addHeaderLine('content-type', 'application/javascript'); } else { $headers->addHeaderLine('content-type', 'application/json'); } }
/** * Inject the response with the XML payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no XML return; } // Populate response /** @var \Zend\Http\Response $response */ $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); $contentType = 'application/xml'; $contentType .= '; charset=' . $this->charset; $headers->addHeaderLine('content-type', $contentType); }
/** * @param ViewEvent $e The ViewEvent instance * @return void */ public function injectResponse($e) { $renderer = $e->getRenderer(); $response = $e->getResponse(); $result = $e->getResult(); if ($renderer === $this->jsonRenderer) { // JSON Renderer; set content-type header $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', 'application/json'); } elseif ($renderer === $this->feedRenderer) { // Feed Renderer; set content-type header, and export the feed if // necessary $feedType = $this->feedRenderer->getFeedType(); $headers = $response->getHeaders(); $mediatype = 'application/' . ('rss' == $feedType ? 'rss' : 'atom') . '+xml'; $headers->addHeaderLine('content-type', $mediatype); // If the $result is a feed, export it if ($result instanceof Feed) { $result = $result->export($feedType); } } elseif ($renderer !== $this->phpRenderer) { // Not a renderer we support, therefor not our strategy. Return return; } // Inject the content $response->setContent($result); }
/** * Inject the response with the JSON payload and appropriate Content-Type header * * @param \Zend\View\ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!$result instanceof NegotiatedResult) { // not a NegotiatedResult, we can't go on here return; } // Populate response $response = $e->getResponse(); $response->setContent($result->content); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', $result->contentType); }
/** * Inject the response with the "Uploader" behavior and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } $result = $e->getResult(); if (!is_string($result)) { return; } // Populate response $response = $e->getResponse(); $result = "<html><head></head><body>" . $result . "</body></html>"; $response->setContent($result); $headers = $response->getHeaders(); $headers->addHeaderLine('content-type', 'text/html; charset=' . $this->charset); if (in_array(strtoupper($this->charset), $this->multibyteCharsets)) { $headers->addHeaderLine('content-transfer-encoding', 'BINARY'); } }
/** * Inject the response with the JSON payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } // Populate response $response = $e->getResponse(); $response->setContent($result); }
/** * Transform the HTML to PDF, * this is a post-rendering-process * * put in here everything related to the transforming-process like options * * @param \Zend\View\ViewEvent $e */ public function attachPDFtransformer(ViewEvent $e) { //$renderer = $e->getRenderer(); $result = $e->getResult(); $response = $e->getResponse(); // the handles are for temporary files error_reporting(0); foreach (array(self::RENDER_FULL, self::RENDER_WITHOUT_PDF, self::RENDER_WITHOUT_ATTACHMENTS) as $render) { $handles = array(); try { $pdf = new extern\mPDFderive(); $pdf->SetImportUse(); // create bookmark list in Acrobat Reader $pdf->h2bookmarks = array('H1' => 0, 'H2' => 1, 'H3' => 2); $pdf->WriteHTML($result); // Output of the Images if (self::RENDER_FULL == $render || self::RENDER_WITHOUT_PDF == $render) { if (is_array($this->appendImage) && !empty($this->appendImage)) { foreach ($this->appendImage as $imageAttachment) { $content = $imageAttachment->getContent(); $url = 'data:image/' . $imageAttachment->getType() . ';base64,' . base64_encode($content); $html = '<a name="attachment_' . $imageAttachment->getId() . '"><img src="' . $url . '" /><br /></a>'; $pdf->WriteHTML($html); } } } // Temp Files PDF if (self::RENDER_FULL == $render) { if (is_array($this->appendPDF) && !empty($this->appendPDF)) { foreach ($this->appendPDF as $pdfAttachment) { $content = $pdfAttachment->getContent(); $tmpHandle = tmpfile(); $handles[] = $tmpHandle; fwrite($tmpHandle, $content); fseek($tmpHandle, 0); } } } // Output of the PDF foreach ($handles as $handle) { $meta_data = stream_get_meta_data($handle); $filename = $meta_data["uri"]; $pdf->WriteHTML($filename); $pagecount = $pdf->SetSourceFile($filename); for ($pages = 0; $pages < $pagecount; $pages++) { $pdf->AddPage(); $pdf->WriteHTML(' pages: ' . $pagecount); $tx = $pdf->ImportPage($pages + 1); $pdf->UseTemplate($tx); } } $pdf_result = $pdf->Output(); $e->setResult($pdf_result); // delete all temporary Files again foreach ($handles as $handle) { fclose($handle); } break; } catch (\Exception $e) { } } error_reporting(E_ALL); }
/** * Inject the response with the JSON payload and appropriate Content-Type header * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $result = $e->getResult(); if (!is_string($result)) { // We don't have a string, and thus, no JSON return; } // Populate response $response = $e->getResponse(); $response->setContent($result); $headers = $response->getHeaders(); if ($this->renderer->hasJsonpCallback()) { $contentType = 'application/javascript'; } else { $contentType = 'application/json'; } $contentType .= '; charset=' . $this->charset; $headers->addHeaderLine('content-type', $contentType); if (in_array(strtoupper($this->charset), $this->multibyteCharsets)) { $headers->addHeaderLine('content-transfer-encoding', 'BINARY'); } }