Example #1
0
 /**
  * @inheritdoc
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \Twig_Error_Syntax
  * @throws \Twig_Error_Loader
  * @throws \Twig_Error_Runtime
  */
 public function __invoke(Payload $payload, ResponseInterface $response)
 {
     /** @var DomainPayload $payload */
     /** @var Page $page */
     $page = $payload->getValue('page', null);
     $status = $payload->getStatus() ?: 200;
     try {
         $response->getBody()->rewind();
         $response->getBody()->write($this->twig->render($page->getRelativeFilePath(), ['page' => $page, 'site' => $this->siteParams]));
         $response = $response->withHeader('Content-Type', 'text/html');
         $response = $response->withHeader('X-Easy-Name', $page->getName());
         return $response->withStatus($status);
     } catch (\Exception $e) {
         $this->logger->debug(sprintf('Twig rendering failed, due to "%s"', $e->getMessage()));
     }
     return null;
 }
Example #2
0
 /**
  * @inheritdoc
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \Twig_Error_Syntax
  * @throws \Twig_Error_Loader
  * @throws \Twig_Error_Runtime
  */
 public function __invoke(Payload $payload, ResponseInterface $response) : ResponseInterface
 {
     if (null === $this->template) {
         throw new \RuntimeException('No template set to render!');
     }
     /** @var \bitExpert\Adrenaline\Domain\DomainPayload $payload */
     $values = $payload->getValues();
     $response->getBody()->rewind();
     $response->getBody()->write($this->twig->render($this->template, $values));
     $headers = array_merge($this->headers, ['Content-Type' => 'text/html']);
     foreach ($headers as $header => $value) {
         $response = $response->withHeader($header, $value);
     }
     /** @var \bitExpert\Adrenaline\Domain\DomainPayload $payload */
     $status = $payload->getStatus() ?: 200;
     return $response->withStatus($status);
 }
 /**
  * {@inheritDoc}
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 public function __invoke(Payload $payload, ResponseInterface $response) : ResponseInterface
 {
     /** @var \bitExpert\Adrenaline\Domain\DomainPayload $payload */
     $filename = $payload->getValue($this->fileAttribute, null);
     if (null === $filename) {
         throw new \InvalidArgumentException(sprintf('Could not find a filename in domain payload attribute "%s"', $this->fileAttribute));
     }
     $file = sprintf('%s/%s.html', $this->basePath, $filename);
     if (!file_exists($file) || !is_readable($file)) {
         throw new \RuntimeException(sprintf('Could not find file "%s" or file is not readable', $file));
     }
     $contents = file_get_contents($file);
     $response->getBody()->rewind();
     $response->getBody()->write($contents);
     $headers = array_merge($this->headers, ['Content-Type' => 'text/html']);
     foreach ($headers as $header => $value) {
         $response = $response->withHeader($header, $value);
     }
     /** @var \bitExpert\Adrenaline\Domain\DomainPayload $payload */
     $status = $payload->getStatus() ?: 200;
     return $response->withStatus($status);
 }