Overview

Namespaces

  • Charcoal
    • Admin
      • Widget
        • Cms
    • Cms
      • Config
      • Mixin
        • Traits
      • Route
      • Section
      • Service
        • Loader
        • Manager
      • ServiceProvider
      • Support
        • Helpers
        • Interfaces
        • Traits
    • Property

Classes

  • Charcoal\Admin\Widget\Cms\HierarchicalSectionTableWidget
  • Charcoal\Admin\Widget\Cms\SectionTableWidget
  • Charcoal\Cms\AbstractDocument
  • Charcoal\Cms\AbstractEvent
  • Charcoal\Cms\AbstractFaq
  • Charcoal\Cms\AbstractImage
  • Charcoal\Cms\AbstractNews
  • Charcoal\Cms\AbstractSection
  • Charcoal\Cms\AbstractText
  • Charcoal\Cms\AbstractVideo
  • Charcoal\Cms\Config
  • Charcoal\Cms\Config\CmsConfig
  • Charcoal\Cms\Config\EventConfig
  • Charcoal\Cms\Config\NewsConfig
  • Charcoal\Cms\Config\SectionConfig
  • Charcoal\Cms\Document
  • Charcoal\Cms\DocumentCategory
  • Charcoal\Cms\EmptySection
  • Charcoal\Cms\Event
  • Charcoal\Cms\EventCategory
  • Charcoal\Cms\ExternalSection
  • Charcoal\Cms\Faq
  • Charcoal\Cms\FaqCategory
  • Charcoal\Cms\Image
  • Charcoal\Cms\ImageCategory
  • Charcoal\Cms\News
  • Charcoal\Cms\NewsCategory
  • Charcoal\Cms\Route\EventRoute
  • Charcoal\Cms\Route\GenericRoute
  • Charcoal\Cms\Route\NewsRoute
  • Charcoal\Cms\Route\SectionRoute
  • Charcoal\Cms\Section
  • Charcoal\Cms\Section\BlocksSection
  • Charcoal\Cms\Section\ContentSection
  • Charcoal\Cms\Service\Loader\AbstractLoader
  • Charcoal\Cms\Service\Loader\EventLoader
  • Charcoal\Cms\Service\Loader\NewsLoader
  • Charcoal\Cms\Service\Loader\SectionLoader
  • Charcoal\Cms\Service\Manager\AbstractManager
  • Charcoal\Cms\Service\Manager\EventManager
  • Charcoal\Cms\Service\Manager\NewsManager
  • Charcoal\Cms\ServiceProvider\CmsServiceProvider
  • Charcoal\Cms\Support\Helpers\DateHelper
  • Charcoal\Cms\Tag
  • Charcoal\Cms\Text
  • Charcoal\Cms\TextCategory
  • Charcoal\Cms\Video
  • Charcoal\Cms\VideoCategory
  • Charcoal\Property\TemplateOptionsProperty
  • Charcoal\Property\TemplateProperty

Interfaces

  • Charcoal\Cms\DocumentInterface
  • Charcoal\Cms\EventInterface
  • Charcoal\Cms\FaqInterface
  • Charcoal\Cms\ImageInterface
  • Charcoal\Cms\MetatagInterface
  • Charcoal\Cms\Mixin\HasContentBlocksInterface
  • Charcoal\Cms\NewsInterface
  • Charcoal\Cms\SearchableInterface
  • Charcoal\Cms\SectionInterface
  • Charcoal\Cms\Support\Interfaces\EventManagerAwareInterface
  • Charcoal\Cms\Support\Interfaces\NewsManagerAwareInterface
  • Charcoal\Cms\Support\Interfaces\SectionLoaderAwareInterface
  • Charcoal\Cms\TemplateableInterface
  • Charcoal\Cms\TextInterface
  • Charcoal\Cms\VideoInterface

Traits

  • Charcoal\Admin\Widget\Cms\SectionTableTrait
  • Charcoal\Cms\MetatagTrait
  • Charcoal\Cms\Mixin\Traits\HasContentBlocksTrait
  • Charcoal\Cms\SearchableTrait
  • Charcoal\Cms\Support\Traits\DateHelperAwareTrait
  • Charcoal\Cms\Support\Traits\EventManagerAwareTrait
  • Charcoal\Cms\Support\Traits\NewsManagerAwareTrait
  • Charcoal\Cms\Support\Traits\SectionLoaderAwareTrait
  • Charcoal\Cms\TemplateableTrait
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Charcoal\Cms\Route;
  4: 
  5: // From Pimple
  6: use Pimple\Container;
  7: 
  8: // From PSR-7
  9: use Psr\Http\Message\RequestInterface;
 10: use Psr\Http\Message\ResponseInterface;
 11: 
 12: // From 'charcoal-translator'
 13: use Charcoal\Translator\TranslatorAwareTrait;
 14: 
 15: // From 'charcoal-app'
 16: use Charcoal\App\Route\TemplateRoute;
 17: 
 18: // From 'charcoal-cms'
 19: use Charcoal\Cms\EventInterface;
 20: use Charcoal\Object\RoutableInterface;
 21: 
 22: /**
 23:  * Event Route Handler
 24:  */
 25: class EventRoute extends TemplateRoute
 26: {
 27:     use TranslatorAwareTrait;
 28: 
 29:     /**
 30:      * URI path.
 31:      *
 32:      * @var string
 33:      */
 34:     private $path;
 35: 
 36:     /**
 37:      * The event object matching the URI path.
 38:      *
 39:      * @var EventInterface|RoutableInterface
 40:      */
 41:     private $event;
 42: 
 43:     /**
 44:      * The event model.
 45:      *
 46:      * @var string
 47:      */
 48:     private $objType = 'charcoal/cms/event';
 49: 
 50:     /**
 51:      * @param array $data Class depdendencies.
 52:      */
 53:     public function __construct(array $data)
 54:     {
 55:         parent::__construct($data);
 56:         $this->path = ltrim($data['path'], '/');
 57:     }
 58: 
 59:     /**
 60:      * Determine if the URI path resolves to an object.
 61:      *
 62:      * @param  Container $container A DI (Pimple) container.
 63:      * @return boolean
 64:      */
 65:     public function pathResolvable(Container $container)
 66:     {
 67:         $event = $this->loadEventFromPath($container);
 68:         return !!$event->id();
 69:     }
 70: 
 71:     /**
 72:      * @param  Container         $container A DI (Pimple) container.
 73:      * @param  RequestInterface  $request   A PSR-7 compatible Request instance.
 74:      * @param  ResponseInterface $response  A PSR-7 compatible Response instance.
 75:      * @return ResponseInterface
 76:      */
 77:     public function __invoke(
 78:         Container $container,
 79:         RequestInterface $request,
 80:         ResponseInterface $response
 81:     ) {
 82:         $config = $this->config();
 83: 
 84:         $event = $this->loadEventFromPath($container);
 85: 
 86:         $templateIdent      = $event->templateIdent();
 87:         $templateController = $event->templateIdent();
 88: 
 89:         if (!$templateController) {
 90:             return $response->withStatus(404);
 91:         }
 92: 
 93:         $templateFactory = $container['template/factory'];
 94: 
 95:         $template = $templateFactory->create($templateController);
 96:         $template->init($request);
 97: 
 98:         // Set custom data from config.
 99:         $template->setData($config['template_data']);
100:         $template->setEvent($event);
101: 
102:         $templateContent = $container['view']->render($templateIdent, $template);
103: 
104:         $response->write($templateContent);
105: 
106:         return $response;
107:     }
108: 
109:     /**
110:      * @todo   Add support for `@see setlocale()`; {@see GenericRoute::setLocale()}
111:      * @param  Container $container Pimple DI container.
112:      * @return EventInterface
113:      */
114:     protected function loadEventFromPath(Container $container)
115:     {
116:         if (!$this->event) {
117:             $config  = $this->config();
118:             $objType = (isset($config['obj_type']) ? $config['obj_type'] : $this->objType);
119: 
120:             $this->event = $container['model/factory']->create($objType);
121:             $this->setTranslator($container['translator']);
122: 
123:             $langs = $container['translator']->availableLocales();
124:             $lang  = $this->event->loadFromL10n('slug', $this->path, $langs);
125:             $container['translator']->setLocale($lang);
126:         }
127: 
128:         return $this->event;
129:     }
130: }
131: 
API documentation generated by ApiGen