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.                 '_controller' => 'Contao\FrontendIndex::renderPage',
  37.                 '_scope' => ContaoCoreBundle::SCOPE_FRONTEND,
  38.                 '_locale' => LocaleUtil::formatAsLocale($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 getOriginalPath(): string
  83.     {
  84.         return parent::getPath();
  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.      * @param mixed $content
  108.      */
  109.     public function setContent($content): self
  110.     {
  111.         $this->content $content;
  112.         return $this;
  113.     }
  114.     public function getContent()
  115.     {
  116.         return $this->content;
  117.     }
  118.     public function getRouteKey(): string
  119.     {
  120.         return 'tl_page.'.$this->pageModel->id;
  121.     }
  122. }