示例#1
0
 /**
  * Handle the error by triggering Splot\Framework\Events\ExceptionDidOccur event.
  */
 public function handle()
 {
     $event = new ExceptionDidOccur($this->getException());
     // trigger the event
     $this->eventManager->trigger($event);
     // only send the response in actual web mode
     $mode = $this->container->getParameter('mode');
     if ($mode == Framework::MODE_WEB && $event->isHandled() && ($response = $event->getResponse())) {
         $response->send();
     }
     if ($event->isDefaultPrevented()) {
         return Handler::QUIT;
     }
     if ($event->isPropagationStopped()) {
         return Handler::LAST_HANDLER;
     }
     return Handler::DONE;
 }
示例#2
0
 /**
  * Generates a static page from the given Page object.
  *
  * @param  Page   $page Page object.
  *
  * @return string
  */
 public function generatePage(Page $page)
 {
     if (!$page->getTemplateFile()->isFile()) {
         throw new NotFoundException('Could not find template to render: ' . $page->getTemplateFile()->getPathname());
     }
     $output = $this->templating->render($page->getTemplateName(), array_merge($page->getParameters(), array('_genry_page' => $page)));
     // trigger event
     $event = new PageRendered($page, $output);
     $this->eventManager->trigger($event);
     // update the final output with the output from the event
     $output = $event->getOutput();
     // make sure that the dir the output will be saved, exists
     $outputDir = $page->getOutputFile()->getPath();
     if (!is_dir($outputDir)) {
         mkdir($outputDir, 0755, true);
     }
     file_put_contents($page->getOutputFile()->getPathname(), $output);
     $this->logger->debug('Generated {output} from {template}', array('output' => $page->getOutputName(), 'template' => $page->getTemplateName()));
     return $output;
 }
示例#3
0
 /**
  * Constructor.
  *
  * @param ContainerInterface $container Splot DI Container for retrieving subscriber services.
  * @param LoggerInterface  $logger    [optional] Logger into which info about called events will be sent. Default: `null`.
  */
 public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
 {
     parent::__construct($logger);
     $this->container = $container;
 }