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\SectionInterface;
 20: use Charcoal\Object\RoutableInterface;
 21: 
 22: /**
 23:  * Section Route Handler
 24:  */
 25: class SectionRoute extends TemplateRoute
 26: {
 27:     use TranslatorAwareTrait;
 28: 
 29:     /**
 30:      * URI path.
 31:      *
 32:      * @var string
 33:      */
 34:     private $path;
 35: 
 36:     /**
 37:      * The section object matching the URI path.
 38:      *
 39:      * @var SectionInterface|RoutableInterface
 40:      */
 41:     private $section;
 42: 
 43:     /**
 44:      * The section model.
 45:      *
 46:      * @var string
 47:      */
 48:     private $objType = 'charcoal/cms/section';
 49: 
 50:     /**
 51:      * @param array $data Class depdendencies.
 52:      */
 53:     public function __construct(array $data)
 54:     {
 55:         parent::__construct($data);
 56: 
 57:         $this->path = ltrim($data['path'], '/');
 58:     }
 59: 
 60:     /**
 61:      * Determine if the URI path resolves to an object.
 62:      *
 63:      * @param  Container $container A DI (Pimple) container.
 64:      * @return boolean
 65:      */
 66:     public function pathResolvable(Container $container)
 67:     {
 68:         $section = $this->loadSectionFromPath($container);
 69:         return !!$section->id();
 70:     }
 71: 
 72:     /**
 73:      * @param  Container         $container A DI (Pimple) container.
 74:      * @param  RequestInterface  $request   A PSR-7 compatible Request instance.
 75:      * @param  ResponseInterface $response  A PSR-7 compatible Response instance.
 76:      * @return ResponseInterface
 77:      */
 78:     public function __invoke(
 79:         Container $container,
 80:         RequestInterface $request,
 81:         ResponseInterface $response
 82:     ) {
 83:         $config = $this->config();
 84: 
 85:         $section = $this->loadSectionFromPath($container);
 86: 
 87:         $templateIdent      = (string)$section->templateIdent();
 88:         $templateController = (string)$section->templateIdent();
 89: 
 90:         if (!$templateController) {
 91:             return $response->withStatus(404);
 92:         }
 93: 
 94:         $templateFactory = $container['template/factory'];
 95:         $templateFactory->setDefaultClass($config['default_controller']);
 96: 
 97:         $template = $templateFactory->create($templateController);
 98:         $template->init($request);
 99: 
100:         // Set custom data from config.
101:         $template->setData($config['template_data']);
102:         $template->setSection($section);
103: 
104:         $templateContent = $container['view']->render($templateIdent, $template);
105: 
106:         $response->write($templateContent);
107: 
108:         return $response;
109:     }
110: 
111:     /**
112:      * @todo   Add support for `@see setlocale()`; {@see GenericRoute::setLocale()}
113:      * @param  Container $container Pimple DI container.
114:      * @return SectionInterface
115:      */
116:     protected function loadSectionFromPath(Container $container)
117:     {
118:         if (!$this->section) {
119:             $config  = $this->config();
120:             $objType = (isset($config['obj_type']) ? $config['obj_type'] : $this->objType);
121: 
122:             $this->section = $container['model/factory']->create($objType);
123: 
124:             $langs = $container['translator']->availableLocales();
125:             $lang  = $this->section->loadFromL10n('slug', $this->path, $langs);
126:             $container['translator']->setLocale($lang);
127:         }
128: 
129:         return $this->section;
130:     }
131: }
132: 
API documentation generated by ApiGen