PagesProcessor.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @package Grav.Common.Processors
  4. *
  5. * @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Processors;
  9. use Grav\Common\Page\Page;
  10. use RocketTheme\Toolbox\Event\Event;
  11. class PagesProcessor extends ProcessorBase implements ProcessorInterface
  12. {
  13. public $id = 'pages';
  14. public $title = 'Pages';
  15. public function process()
  16. {
  17. // Dump Cache state
  18. $this->container['debugger']->addMessage($this->container['cache']->getCacheStatus());
  19. $this->container['pages']->init();
  20. $this->container->fireEvent('onPagesInitialized', new Event(['pages' => $this->container['pages']]));
  21. $this->container->fireEvent('onPageInitialized', new Event(['page' => $this->container['page']]));
  22. /** @var Page $page */
  23. $page = $this->container['page'];
  24. if (!$page->routable()) {
  25. // If no page found, fire event
  26. $event = $this->container->fireEvent('onPageNotFound', new Event(['page' => $page]));
  27. if (isset($event->page)) {
  28. unset ($this->container['page']);
  29. $this->container['page'] = $event->page;
  30. } else {
  31. throw new \RuntimeException('Page Not Found', 404);
  32. }
  33. }
  34. }
  35. }