From: Benni Mack Date: Tue, 14 Aug 2018 13:09:49 +0000 (+0200) Subject: [TASK] Remove dependency between SiteLanguage and Site X-Git-Tag: v9.4.0~225 X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/commitdiff_plain/e91b54cf0be9b5195bca0802491edcb7cf7a65dc?hp=36b7cf4bb0637227a4d1af33cb6f53ff5235d5de;ds=sidebyside [TASK] Remove dependency between SiteLanguage and Site The entity of SiteLanguage is re-connected to a site. However this circular dependency makes it impossible to serialize or compile any of the site configuration. As this was introduced at the very early stage of Site Handling where the API wasn't clear, this can be removed, as "site" and "language" are both always available in a PSR-7 request. Resolves: #85841 Releases: master Change-Id: Id061def7b0299b9c355ae83e1903cf64b6127149 Reviewed-on: https://review.typo3.org/57893 Reviewed-by: Benni Mack Tested-by: TYPO3com Reviewed-by: Andreas Fernandez Tested-by: Andreas Fernandez Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- diff --git a/typo3/sysext/core/Classes/Site/Entity/Site.php b/typo3/sysext/core/Classes/Site/Entity/Site.php index 1eefcb464658..85b7ba45170c 100644 --- a/typo3/sysext/core/Classes/Site/Entity/Site.php +++ b/typo3/sysext/core/Classes/Site/Entity/Site.php @@ -107,7 +107,6 @@ class Site implements SiteInterface $base = $this->sanitizeBaseUrl(rtrim($this->base, '/') . '/'); } $this->languages[$languageUid] = new SiteLanguage( - $this, $languageUid, $languageConfiguration['locale'], $base, diff --git a/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php b/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php index 4233f078611d..2c9ff62a10ac 100644 --- a/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php +++ b/typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php @@ -21,11 +21,6 @@ namespace TYPO3\CMS\Core\Site\Entity; */ class SiteLanguage { - /** - * @var SiteInterface - */ - protected $site; - /** * The language mapped to the sys_language DB entry. * @@ -112,15 +107,13 @@ class SiteLanguage /** * SiteLanguage constructor. - * @param SiteInterface $site * @param int $languageId * @param string $locale * @param string $base * @param array $attributes */ - public function __construct(SiteInterface $site, int $languageId, string $locale, string $base, array $attributes) + public function __construct(int $languageId, string $locale, string $base, array $attributes) { - $this->site = $site; $this->languageId = $languageId; $this->locale = $locale; $this->base = $base; @@ -178,14 +171,6 @@ class SiteLanguage ]; } - /** - * @return SiteInterface - */ - public function getSite(): SiteInterface - { - return $this->site; - } - /** * @return int */ diff --git a/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php b/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php index 0a9cd41102f6..46132b9ffbaf 100644 --- a/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php +++ b/typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php @@ -19,6 +19,7 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractConditionMatcher; use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Context\UserAspect; +use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -96,9 +97,8 @@ class ConditionMatcher extends AbstractConditionMatcher } break; case 'site': - $siteLanguage = $this->getCurrentSiteLanguage(); - if ($siteLanguage instanceof SiteLanguage) { - $site = $siteLanguage->getSite(); + $site = $this->getCurrentSite(); + if ($site instanceof Site) { $values = GeneralUtility::trimExplode(',', $value, true); foreach ($values as $test) { $point = strcspn($test, '='); @@ -300,4 +300,18 @@ class ConditionMatcher extends AbstractConditionMatcher } return null; } + + /** + * Returns the currently configured site if a site is configured (= resolved) in the current request. + * + * @internal + */ + protected function getCurrentSite(): ?Site + { + if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface + && $GLOBALS['TYPO3_REQUEST']->getAttribute('site') instanceof Site) { + return $GLOBALS['TYPO3_REQUEST']->getAttribute('site'); + } + return null; + } } diff --git a/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php b/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php index de3e45dcfce7..27e8a6e5dfa4 100644 --- a/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php +++ b/typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php @@ -793,7 +793,7 @@ class ConditionMatcherTest extends UnitTestCase { $site = new Site('angelo', 13, ['languages' => [], 'base' => 'https://typo3.org/']); $GLOBALS['TYPO3_REQUEST'] = new ServerRequest(); - $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0)); + $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('site', $site); $subject = new ConditionMatcher(new Context()); $this->assertTrue($subject->match('[site = identifier = angelo]')); $this->assertTrue($subject->match('[site = rootPageId = 13]')); @@ -822,7 +822,7 @@ class ConditionMatcherTest extends UnitTestCase ] ]); $GLOBALS['TYPO3_REQUEST'] = new ServerRequest(); - $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0)); + $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('site', $site); $subject = new ConditionMatcher(new Context()); $this->assertFalse($subject->match('[site = identifier = berta]')); $this->assertFalse($subject->match('[site = rootPageId = 14, rootPageId=23]'));