‪TYPO3CMS  9.5
PseudoSite.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Psr\Http\Message\UriInterface;
21 
27 class ‪PseudoSite extends ‪NullSite implements ‪SiteInterface
28 {
32  protected ‪$entryPoints;
33 
38  protected ‪$domainRecords = [];
39 
46  public function ‪__construct(int ‪$rootPageId, array $configuration)
47  {
48  $this->rootPageId = ‪$rootPageId;
49  foreach ($configuration['domains'] ?? [] as $domain) {
50  if (empty($domain['domainName'] ?? false)) {
51  continue;
52  }
53  $this->domainRecords[] = $domain;
54  $this->entryPoints[] = new ‪Uri($this->‪sanitizeBaseUrl($domain['domainName'] ?: ''));
55  }
56  if (empty($this->entryPoints)) {
57  $this->entryPoints = [new ‪Uri('/')];
58  }
59  $baseEntryPoint = reset($this->entryPoints);
60 
61  parent::__construct($configuration['languages'], $baseEntryPoint);
62  }
63 
69  public function ‪getIdentifier(): string
70  {
71  return '#PSEUDO_' . ‪$this->rootPageId;
72  }
73 
77  public function ‪getBase(): UriInterface
78  {
79  return $this->entryPoints[0] ?? new ‪Uri('/');
80  }
81 
87  public function ‪getEntryPoints(): array
88  {
89  return ‪$this->entryPoints;
90  }
91 
97  public function ‪getRootPageId(): int
98  {
99  return ‪$this->rootPageId;
100  }
101 
109  protected function ‪sanitizeBaseUrl(string $base): string
110  {
111  // no protocol ("//") and the first part is no "/" (path), means that this is a domain like
112  // "www.domain.com/subpage", and we want to ensure that this one then gets a "no-scheme agnostic" part
113  if (!empty($base) && strpos($base, '//') === false && $base[0] !== '/') {
114  // either a scheme is added, or no scheme but with domain, or a path which is not absolute
115  // make the base prefixed with a slash, so it is recognized as path, not as domain
116  // treat as path
117  if (strpos($base, '.') === false) {
118  $base = '/' . $base;
119  } else {
120  // treat as domain name
121  $base = '//' . $base;
122  }
123  }
124  return $base;
125  }
126 }
‪TYPO3\CMS\Core\Site\Entity\SiteInterface
Definition: SiteInterface.php:25
‪TYPO3\CMS\Core\Site\Entity\NullSite
Definition: NullSite.php:31
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\$domainRecords
‪array $domainRecords
Definition: PseudoSite.php:36
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:27
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\$entryPoints
‪string[] $entryPoints
Definition: PseudoSite.php:31
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\getEntryPoints
‪UriInterface[] getEntryPoints()
Definition: PseudoSite.php:85
‪TYPO3\CMS\Core\Site\Entity
Definition: NullSite.php:4
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\getRootPageId
‪int getRootPageId()
Definition: PseudoSite.php:95
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\getBase
‪getBase()
Definition: PseudoSite.php:75
‪TYPO3\CMS\Core\Site\Entity\PseudoSite
Definition: PseudoSite.php:28
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\__construct
‪__construct(int $rootPageId, array $configuration)
Definition: PseudoSite.php:44
‪TYPO3\CMS\Core\Site\Entity\NullSite\$rootPageId
‪int $rootPageId
Definition: NullSite.php:34
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\getIdentifier
‪string getIdentifier()
Definition: PseudoSite.php:67
‪TYPO3\CMS\Core\Site\Entity\PseudoSite\sanitizeBaseUrl
‪string sanitizeBaseUrl(string $base)
Definition: PseudoSite.php:107