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.     private PageModel $pageModel;
  19.     private ?string $urlPrefix;
  20.     private ?string $urlSuffix;
  21.     /**
  22.      * The referenced content object (can be anything).
  23.      *
  24.      * @var mixed
  25.      */
  26.     private $content;
  27.     /**
  28.      * @param string|array<string> $methods
  29.      */
  30.     public function __construct(PageModel $pageModelstring $path '', array $defaults = [], array $requirements = [], array $options = [], $methods = [])
  31.     {
  32.         $pageModel->loadDetails();
  33.         $defaults array_merge(
  34.             [
  35.                 '_token_check' => true,
  36.                 '_controller' => 'Contao\FrontendIndex::renderPage',
  37.                 '_scope' => ContaoCoreBundle::SCOPE_FRONTEND,
  38.                 '_locale' => LocaleUtil::formatAsLocale((string) $pageModel->rootLanguage),
  39.                 '_format' => 'html',
  40.                 '_canonical_route' => 'tl_page.'.$pageModel->id,
  41.             ],
  42.             $defaults
  43.         );
  44.         // Always use the given page model in the defaults
  45.         $defaults['pageModel'] = $pageModel;
  46.         if (!isset($options['utf8'])) {
  47.             $options['utf8'] = true;
  48.         }
  49.         if (!isset($options['compiler_class'])) {
  50.             $options['compiler_class'] = PageRouteCompiler::class;
  51.         }
  52.         if ('' === $path) {
  53.             $path '/'.($pageModel->alias ?: $pageModel->id);
  54.         } elseif (!== strncmp($path'/'1)) {
  55.             $path '/'.($pageModel->alias ?: $pageModel->id).'/'.$path;
  56.         }
  57.         parent::__construct(
  58.             $path,
  59.             $defaults,
  60.             $requirements,
  61.             $options,
  62.             $pageModel->domain,
  63.             $pageModel->rootUseSSL 'https' 'http',
  64.             $methods
  65.         );
  66.         $this->pageModel $pageModel;
  67.         $this->urlPrefix $pageModel->urlPrefix;
  68.         $this->urlSuffix $pageModel->urlSuffix;
  69.     }
  70.     public function getPageModel(): PageModel
  71.     {
  72.         return $this->pageModel;
  73.     }
  74.     public function getPath(): string
  75.     {
  76.         $path parent::getPath();
  77.         if ('' !== $this->getUrlPrefix()) {
  78.             $path '/'.$this->getUrlPrefix().$path;
  79.         }
  80.         return $path.$this->getUrlSuffix();
  81.     }
  82.     public function getUrlPrefix(): string
  83.     {
  84.         return $this->urlPrefix;
  85.     }
  86.     public function setUrlPrefix(string $urlPrefix): self
  87.     {
  88.         $this->urlPrefix $urlPrefix;
  89.         return $this;
  90.     }
  91.     public function getUrlSuffix(): string
  92.     {
  93.         return $this->urlSuffix;
  94.     }
  95.     public function setUrlSuffix(string $urlSuffix): self
  96.     {
  97.         $this->urlSuffix $urlSuffix;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Sets the object this URL points to.
  102.      *
  103.      * @param mixed $content
  104.      */
  105.     public function setContent($content): self
  106.     {
  107.         $this->content $content;
  108.         return $this;
  109.     }
  110.     public function getContent()
  111.     {
  112.         return $this->content;
  113.     }
  114.     public function getRouteKey(): string
  115.     {
  116.         return 'tl_page.'.$this->pageModel->id;
  117.     }
  118. }