Skip to content

Commit 5fa5412

Browse files
committed
[TASK] Introduce a Proxy for SiteFinder
1 parent f3a91d7 commit 5fa5412

File tree

5 files changed

+62
-15
lines changed

5 files changed

+62
-15
lines changed

Classes/Proxy/SiteFinderProxy.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace FluidTYPO3\Vhs\Proxy;
3+
4+
/*
5+
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6+
*
7+
* For the full copyright and license information, please read the
8+
* LICENSE.md file that was distributed with this source code.
9+
*/
10+
11+
use TYPO3\CMS\Core\Site\Entity\Site;
12+
use TYPO3\CMS\Core\Site\SiteFinder;
13+
14+
/**
15+
* Final/readonly classes are the worst decision in TYPO3 since Neos.
16+
*
17+
* @codeCoverageIgnore
18+
*/
19+
class SiteFinderProxy
20+
{
21+
private SiteFinder $siteFinder;
22+
23+
public function __construct(SiteFinder $siteFinder)
24+
{
25+
$this->siteFinder = $siteFinder;
26+
}
27+
public function getAllSites(bool $useCache = true): array
28+
{
29+
return $this->siteFinder->getAllSites($useCache);
30+
}
31+
32+
public function getSiteByRootPageId(int $rootPageId): Site
33+
{
34+
return $this->siteFinder->getSiteByRootPageId($rootPageId);
35+
}
36+
37+
public function getSiteByIdentifier(string $identifier): Site
38+
{
39+
return $this->siteFinder->getSiteByIdentifier($identifier);
40+
}
41+
42+
public function getSiteByPageId(int $pageId, ?array $rootLine = null, ?string $mountPointParameter = null): Site
43+
{
44+
return $this->siteFinder->getSiteByPageId($pageId, $rootLine, $mountPointParameter);
45+
}
46+
}

Classes/Utility/FrontendSimulationUtility.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
* LICENSE.md file that was distributed with this source code.
99
*/
1010

11+
use FluidTYPO3\Vhs\Proxy\SiteFinderProxy;
1112
use TYPO3\CMS\Core\Context\Context;
1213
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
1314
use TYPO3\CMS\Core\Routing\PageArguments;
1415
use TYPO3\CMS\Core\Site\Entity\Site;
15-
use TYPO3\CMS\Core\Site\SiteFinder;
1616
use TYPO3\CMS\Core\Utility\GeneralUtility;
1717
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
1818
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -36,8 +36,8 @@ public static function simulateFrontendEnvironment(): ?TypoScriptFrontendControl
3636

3737
$GLOBALS['TYPO3_CONF_VARS']['FE']['cookieName'] = $GLOBALS['TYPO3_CONF_VARS']['FE']['cookieName'] ?? 'fe_user';
3838

39-
/** @var SiteFinder $siteFinder */
40-
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
39+
/** @var SiteFinderProxy $siteFinder */
40+
$siteFinder = GeneralUtility::makeInstance(SiteFinderProxy::class);
4141
$sites = $siteFinder->getAllSites();
4242
/** @var Context $context */
4343
$context = GeneralUtility::makeInstance(Context::class);

Classes/ViewHelpers/Page/LanguageMenuViewHelper.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
use FluidTYPO3\Vhs\Proxy\DoctrineQueryProxy;
12+
use FluidTYPO3\Vhs\Proxy\SiteFinderProxy;
1213
use FluidTYPO3\Vhs\Traits\ArrayConsumingViewHelperTrait;
1314
use FluidTYPO3\Vhs\Traits\TagViewHelperCompatibility;
1415
use FluidTYPO3\Vhs\Utility\ContentObjectFetcher;
@@ -19,7 +20,6 @@
1920
use TYPO3\CMS\Core\Imaging\Icon;
2021
use TYPO3\CMS\Core\Imaging\IconFactory;
2122
use TYPO3\CMS\Core\Site\Site;
22-
use TYPO3\CMS\Core\Site\SiteFinder;
2323
use TYPO3\CMS\Core\Utility\GeneralUtility;
2424
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
2525
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
@@ -152,12 +152,10 @@ public function render()
152152
$this->cObj = $contentObject;
153153
$this->tagName = is_scalar($this->arguments['tagName']) ? (string) $this->arguments['tagName'] : 'ul';
154154
$this->tag->setTagName($this->tagName);
155-
156-
if (class_exists(SiteFinder::class)) {
157-
$this->site = $this->getSite();
158-
$this->defaultLangUid = $this->site->getDefaultLanguage()->getLanguageId();
159-
}
155+
$this->site = $this->getSite();
156+
$this->defaultLangUid = $this->site->getDefaultLanguage()->getLanguageId();
160157
$this->languageMenu = $this->parseLanguageMenu();
158+
161159
/** @var string $as */
162160
$as = $this->arguments['as'];
163161
$this->renderingContext->getVariableProvider()->add($as, $this->languageMenu);
@@ -505,8 +503,8 @@ protected function getPageUid(): int
505503
*/
506504
protected function getSite()
507505
{
508-
/** @var SiteFinder $siteFinder */
509-
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
506+
/** @var SiteFinderProxy $siteFinder */
507+
$siteFinder = GeneralUtility::makeInstance(SiteFinderProxy::class);
510508
return $siteFinder->getSiteByPageId($this->getPageUid());
511509
}
512510

Configuration/Services.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ services:
1111
FluidTYPO3\Vhs\:
1212
resource: '../Classes/*'
1313

14-
FluidTYPO3\Vhs\Utility\DispatcherProxy:
14+
FluidTYPO3\Vhs\Proxy\DispatcherProxy:
15+
public: true
16+
17+
FluidTYPO3\Vhs\Proxy\SiteFinderProxy:
1518
public: true
1619

1720
FluidTYPO3\Vhs\Service\AssetService:

Tests/Unit/Utility/FrontendSimulationUtilityTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* LICENSE.md file that was distributed with this source code.
99
*/
1010

11+
use FluidTYPO3\Vhs\Proxy\SiteFinderProxy;
1112
use FluidTYPO3\Vhs\Tests\Unit\AbstractTestCase;
1213
use FluidTYPO3\Vhs\Utility\FrontendSimulationUtility;
1314
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
1415
use TYPO3\CMS\Core\Http\ServerRequest;
1516
use TYPO3\CMS\Core\Site\Entity\Site;
1617
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
17-
use TYPO3\CMS\Core\Site\SiteFinder;
1818
use TYPO3\CMS\Core\Utility\GeneralUtility;
1919
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
2020
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
->getMock();
3838
$site->method('getDefaultLanguage')->willReturn($siteLanguage);
3939

40-
$siteFinder = $this->getMockBuilder(SiteFinder::class)
40+
$siteFinder = $this->getMockBuilder(SiteFinderProxy::class)
4141
->setMethods(['getAllSites'])
4242
->disableOriginalConstructor()
4343
->getMock();
@@ -47,7 +47,7 @@ protected function setUp(): void
4747
->disableOriginalConstructor()
4848
->getMock();
4949

50-
GeneralUtility::addInstance(SiteFinder::class, $siteFinder);
50+
GeneralUtility::addInstance(SiteFinderProxy::class, $siteFinder);
5151
GeneralUtility::addInstance(FrontendUserAuthentication::class, $frontendUserAuthentication);
5252
GeneralUtility::addInstance(
5353
TypoScriptFrontendController::class,

0 commit comments

Comments
 (0)