/** * {@inheritdoc} */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { try { $page = new Page($this->basePath, $this->defaultPage); return $response->withStatus(301)->withHeader('Location', '/' . $page->getName()); } catch (\Exception $e) { $this->logger->debug(sprintf('Page creation failed, due to "%s"', $e->getMessage())); } return $response->withStatus(404); }
/** * {{@inheritDoc}} */ public function __invoke(Page $page, $blockname, array $params = []) { /** @var \Twig_Template $template */ $template = $this->twigEnv->loadTemplate($page->getRelativeFilePath()); if (!$template->hasBlock($blockname)) { $this->logger->debug(sprintf('Block "%s" not found in Page "%s" source file', $blockname, $page->getName())); return ''; } return $template->renderBlock($blockname, $this->twigEnv->mergeGlobals($params)); }
/** * Exports a page by firing a request against the Adrenaline middleware. * * @param Page $page * @param OutputInterface $output */ protected function exportPage(Page $page, OutputInterface $output) { $output->write(sprintf('Exporting page %s ', $page->getName())); try { $request = ServerRequestFactory::fromGlobals(); $response = new Response(); $app = $this->app; $request = $request->withUri(new Uri('/' . $page->getName())); $app($request, $response); $output->writeln('OK'); } catch (\Exception $e) { $output->writeln('FAILED!'); $this->logger->debug(sprintf('Export for "%s" failed: %s', $page->getName(), $e->getMessage())); } }