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