siteConfiguration->getAllExistingSites($useCache); } /** * Find a site by given root page id * * @param int $rootPageId the page ID (default language) * @throws SiteNotFoundException * @internal only for usage in some places for managing Site Configuration, might be removed without further notice */ public function getSiteByRootPageId(int $rootPageId): Site { $mapping = $this->getRootPageIdToIdentifierMapping(); $sites = $this->siteConfiguration->getAllExistingSites(); if (isset($mapping[$rootPageId], $sites[$mapping[$rootPageId]])) { return $sites[$mapping[$rootPageId]]; } throw new SiteNotFoundException('No site found for root page id ' . $rootPageId, 1521668882); } /** * Find a site by given identifier * * @throws SiteNotFoundException */ public function getSiteByIdentifier(string $identifier): Site { $sites = $this->siteConfiguration->getAllExistingSites(); if (isset($sites[$identifier])) { return $sites[$identifier]; } throw new SiteNotFoundException('No site found for identifier ' . $identifier, 1521716628); } /** * Traverses the rootline of a page up until a Site was found. * * @param string|null $mountPointParameter * @throws SiteNotFoundException */ public function getSiteByPageId(int $pageId, ?array $rootLine = null, ?string $mountPointParameter = null): Site { if ($pageId === 0) { // page uid 0 has no root line. We don't need to ask the root line resolver to know that. $rootLine = []; } if (!is_array($rootLine)) { try { $rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, (string)$mountPointParameter)->get(); } catch (PageNotFoundException) { // Usually when a page was hidden or disconnected // This could be improved by handing in a Context object and decide whether hidden pages // Should be linkable too $rootLine = []; } } $sites = $this->siteConfiguration->getAllExistingSites(); $mapping = $this->getRootPageIdToIdentifierMapping(); foreach ($rootLine as $pageInRootLine) { if (isset($mapping[(int)$pageInRootLine['uid']], $sites[$mapping[(int)$pageInRootLine['uid']]])) { return $sites[$mapping[(int)$pageInRootLine['uid']]]; } } throw new SiteNotFoundException('No site found in root line of page ' . $pageId, 1521716622); } #[AsEventListener(event: SiteConfigurationChangedEvent::class)] public function siteConfigurationChanged(): void { $this->runtimeCache->remove(self::CACHE_IDENTIFIER_ROOT_ID_TO_IDENTIFIER); } private function getRootPageIdToIdentifierMapping(): array { $mapping = $this->runtimeCache->get(self::CACHE_IDENTIFIER_ROOT_ID_TO_IDENTIFIER); if (is_array($mapping)) { return $mapping; } $sites = $this->siteConfiguration->getAllExistingSites(); $mapping = []; foreach ($sites as $identifier => $site) { $mapping[$site->getRootPageId()] = $identifier; } $this->runtimeCache->set(self::CACHE_IDENTIFIER_ROOT_ID_TO_IDENTIFIER, $mapping); return $mapping; } }