vendor/contao/core-bundle/src/Routing/Page/PageRoute.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle\Routing\Page;
  11. use Contao\CoreBundle\ContaoCoreBundle;
  12. use Contao\CoreBundle\Util\LocaleUtil;
  13. use Contao\PageModel;
  14. use Symfony\Cmf\Component\Routing\RouteObjectInterface;
  15. use Symfony\Component\Routing\Route;
  16. class PageRoute extends Route implements RouteObjectInterface
  17. {
  18.     /**
  19.      * @var PageModel
  20.      */
  21.     private $pageModel;
  22.     /**
  23.      * @var string
  24.      */
  25.     private $urlPrefix;
  26.     /**
  27.      * @var string
  28.      */
  29.     private $urlSuffix;
  30.     /**
  31.      * The referenced content object.
  32.      */
  33.     private $content;
  34.     /**
  35.      * @param string|array<string> $methods
  36.      */
  37.     public function __construct(PageModel $pageModelstring $path '', array $defaults = [], array $requirements = [], array $options = [], $methods = [])
  38.     {
  39.         $pageModel->loadDetails();
  40.         $defaults array_merge(
  41.             [
  42.                 '_token_check' => true,
  43.                 '_controller' => 'Contao\FrontendIndex::renderPage',
  44.                 '_scope' => ContaoCoreBundle::SCOPE_FRONTEND,
  45.                 '_locale' => LocaleUtil::formatAsLocale($pageModel->rootLanguage),
  46.                 '_format' => 'html',
  47.                 '_canonical_route' => 'tl_page.'.$pageModel->id,
  48.             ],
  49.             $defaults
  50.         );
  51.         // Always use the given page model in the defaults
  52.         $defaults['pageModel'] = $pageModel;
  53.         if (!isset($options['utf8'])) {
  54.             $options['utf8'] = true;
  55.         }
  56.         if ('' === $path) {
  57.             $path '/'.($pageModel->alias ?: $pageModel->id);
  58.         } elseif (!== strncmp($path'/'1)) {
  59.             $path '/'.($pageModel->alias ?: $pageModel->id).'/'.$path;
  60.         }
  61.         parent::__construct(
  62.             $path,
  63.             $defaults,
  64.             $requirements,
  65.             $options,
  66.             $pageModel->domain,
  67.             $pageModel->rootUseSSL 'https' 'http',
  68.             $methods
  69.         );
  70.         $this->pageModel $pageModel;
  71.         $this->urlPrefix $pageModel->urlPrefix;
  72.         $this->urlSuffix $pageModel->urlSuffix;
  73.     }
  74.     public function getPageModel(): PageModel
  75.     {
  76.         return $this->pageModel;
  77.     }
  78.     public function getPath(): string
  79.     {
  80.         $path parent::getPath();
  81.         if ('' !== $this->getUrlPrefix()) {
  82.             $path '/'.$this->getUrlPrefix().$path;
  83.         }
  84.         return $path.$this->getUrlSuffix();
  85.     }
  86.     public function getUrlPrefix(): string
  87.     {
  88.         return $this->urlPrefix;
  89.     }
  90.     public function setUrlPrefix(string $urlPrefix): self
  91.     {
  92.         $this->urlPrefix $urlPrefix;
  93.         return $this;
  94.     }
  95.     public function getUrlSuffix(): string
  96.     {
  97.         return $this->urlSuffix;
  98.     }
  99.     public function setUrlSuffix(string $urlSuffix): self
  100.     {
  101.         $this->urlSuffix $urlSuffix;
  102.         return $this;
  103.     }
  104.     /**
  105.      * Sets the object this URL points to.
  106.      */
  107.     public function setContent($object): self
  108.     {
  109.         $this->content $object;
  110.         return $this;
  111.     }
  112.     public function getContent()
  113.     {
  114.         return $this->content;
  115.     }
  116.     public function getRouteKey(): string
  117.     {
  118.         return 'tl_page.'.$this->pageModel->id;
  119.     }
  120. }