/** * 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 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 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); }
/** * 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); }
/** * Populate the response object from the View * * Populates the content of the response object from the view rendering * results. * * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer !== $this->renderer) { return; } }
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'); } }
/** * @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); }
/** * {@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)); }
/** * 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) { $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 !== $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)); }
/** * 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 Icalendar payload and appropriate Content-Type header * * @param \Zend\View\ViewEvent $oEvent * * @return void */ public function injectResponse(\Zend\View\ViewEvent $oEvent) { $oRenderer = $oEvent->getRenderer(); if ($oRenderer !== $this->renderer) { // Discovered renderer is not ours; do nothing return; } $sResult = $oEvent->getResult(); if (!is_string($sResult)) { // We don't have a string, and thus, no XML return; } // Populate response $oResponse = $oEvent->getResponse(); $oResponse->setContent($sResult); $oHeaders = $oResponse->getHeaders(); $oHeaders->addHeaderLine('content-type', 'text/calendar; charset=' . $this->charset); }
/** * 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); }
/** * 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) { $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); }
/** * Include the PIWIK-Tracking-code into every page. * * @param $event */ public function addPiwikCode(ViewEvent $event) { $model = $event->getModel(); if (!$model instanceof \Zend\View\Model\ViewModel) { return; } // Return if this is a subrenderer. Therefore we only render once! $options = $model->getOptions(); if (array_key_exists('has_parent', $options) && $options['has_parent']) { return; } $renderer = $event->getRenderer(); if (!$renderer instanceof \Zend\View\Renderer\PhpRenderer) { return; } $config = $this->serviceManager->get('config'); $piwikConfig = $config['orgHeiglPiwik']; $code = str_replace(array_map(function ($e) { return '%%' . $e . '%%'; }, array_keys($piwikConfig)), array_values($piwikConfig), $this->template); $renderer->headScript()->appendScript('//<![CDATA[' . "\n" . $code . "\n" . '//]]>'); return $renderer; }
/** * 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 default values for multiple view plugins * * @param \Zend\View\ViewEvent $event * @return void */ public function injectDefaults(ViewEvent $event) { $view = $event->getRenderer(); if ($view instanceof PhpRenderer) { $hash = spl_object_hash($view); if (!empty($this->injected[$hash])) { return; } $this->injected[$hash] = true; foreach ($this->definitions as $helper => $data) { $plugin = $view->plugin($helper); if ($data instanceof Traversable) { $data = ArrayUtils::iteratorToArray($data); } else { $data = (array) $data; } switch (strtolower($helper)) { case 'headtitle': $contentSet = false; if (isset($data['content'])) { foreach (array_reverse((array) $data['content']) as $content) { if ($content) { $contentSet = true; $plugin($content, AbstractContainer::PREPEND); } } unset($data['content']); } if (!$contentSet) { $plugin(static::DEFAULT_TITLE, AbstractContainer::PREPEND); } if (isset($data['separator'])) { $plugin->setSeparator(' ' . trim($data['separator']) . ' '); unset($data['separator']); } foreach ($data as $key => $value) { $method = 'set' . ucfirst($key); if (method_exists($plugin, $method)) { $plugin->{$method}($value); } else { $plugin->{$key} = $value; } } break; case 'headmeta': $metas = null; foreach (array_reverse($data) as $key => $spec) { if (!empty($spec['content'])) { $content = $spec['content']; unset($spec['content']); if (!empty($spec['http-equiv'])) { $keyType = 'http-equiv'; $keyValue = $spec['http-equiv']; unset($spec['http-equiv']); } elseif (!empty($spec['name'])) { $keyType = 'name'; $keyValue = $spec['name']; unset($spec['name']); } else { $keyType = 'name'; $keyValue = $key; } if ($keyType == 'name' && isset($this->appendableHeadMetaNames[$keyValue])) { if (null === $metas) { $metas = $plugin->getContainer()->getArrayCopy(); } $content .= rtrim($this->appendableHeadMetaNames[$keyValue][2] . preg_replace($this->appendableHeadMetaNames[$keyValue][0], $this->appendableHeadMetaNames[$keyValue][1], $this->getMetaByName($metas, $keyValue)), $this->appendableHeadMetaNames[$keyValue][3]); $plugin->setName($keyValue, $content, $spec); } else { $plugin($content, $keyValue, $keyType, $spec, AbstractContainer::PREPEND); } } } break; case 'headscript': case 'inlinescript': foreach (array_reverse($data) as $spec) { if (!empty($spec['src'])) { $mode = HeadScript::FILE; $content = $spec['src']; unset($spec['src']); } elseif (!empty($spec['script'])) { $mode = HeadScript::SCRIPT; $content = $spec['script']; unset($spec['script']); } else { continue; } if (!empty($spec['type'])) { $type = $spec['type']; unset($spec['type']); } else { $type = 'text/javascript'; } $plugin($mode, $content, AbstractContainer::PREPEND, $spec, $type); } break; case 'headstyle': foreach (array_reverse($data) as $spec) { if (!empty($spec['content'])) { $content = $spec['content']; unset($spec['content']); $plugin($content, AbstractContainer::PREPEND, $spec); } } break; case 'headlink': foreach (array_reverse($data) as $spec) { if (!empty($spec['href'])) { if (empty($spec['rel'])) { $spec['rel'] = 'stylesheet'; } foreach ((array) $spec['rel'] as $rel) { $plugin(ArrayUtils::merge($spec, array('rel' => $rel)), AbstractContainer::PREPEND); } } } break; default: if (is_callable($plugin)) { foreach (array_reverse($data) as $spec) { $plugin((array) $spec, AbstractContainer::PREPEND); } } break; } } } }
/** * @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); }
/** * @param ViewEvent $e * @param array $styles * @return void */ protected function setupHeadStyles(ViewEvent $e, array $styles) { $renderer = $e->getRenderer(); $plugin = $renderer->plugin('headStyle'); foreach ($styles as $style) { list($action, $index) = $this->getPluginAction($style); $content = isset($style['content']) ? $style['content'] : null; $attributes = isset($style['attributes']) ? $style['attributes'] : []; if ($action) { $method = $action . 'Style'; if (null === $index) { $plugin->{$method}($content, $attributes); } else { $plugin->{$method}($index, $content, $attributes); } continue; } $plugin($content, static::ACTION_DEFAULT, $content); } }
/** * 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'); } }
/** * Restore the default PhpRenderer, in order to let Zend\View\Strategy\PhpRendererStrategy * to trigger his injectResponse() * * @param ViewEvent $e */ public function restoreRenderer(ViewEvent $e) { $renderer = $e->getRenderer(); if ($renderer === $this) { $e->setRenderer($this->getDefaultPhpRenderer()); } }
/** * 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); }
/** * 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'); } }