[TASK] Remove dependency between SiteLanguage and Site 93/57893/4
authorBenni Mack <benni@typo3.org>
Tue, 14 Aug 2018 13:09:49 +0000 (15:09 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 14 Aug 2018 17:25:26 +0000 (19:25 +0200)
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 <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Site/Entity/Site.php
typo3/sysext/core/Classes/Site/Entity/SiteLanguage.php
typo3/sysext/frontend/Classes/Configuration/TypoScript/ConditionMatching/ConditionMatcher.php
typo3/sysext/frontend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php

index 1eefcb4..85b7ba4 100644 (file)
@@ -107,7 +107,6 @@ class Site implements SiteInterface
                 $base = $this->sanitizeBaseUrl(rtrim($this->base, '/') . '/');
             }
             $this->languages[$languageUid] = new SiteLanguage(
-                $this,
                 $languageUid,
                 $languageConfiguration['locale'],
                 $base,
index 4233f07..2c9ff62 100644 (file)
@@ -22,11 +22,6 @@ namespace TYPO3\CMS\Core\Site\Entity;
 class SiteLanguage
 {
     /**
-     * @var SiteInterface
-     */
-    protected $site;
-
-    /**
      * The language mapped to the sys_language DB entry.
      *
      * @var int
@@ -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;
@@ -179,14 +172,6 @@ class SiteLanguage
     }
 
     /**
-     * @return SiteInterface
-     */
-    public function getSite(): SiteInterface
-    {
-        return $this->site;
-    }
-
-    /**
      * @return int
      */
     public function getLanguageId(): int
index 0a9cd41..46132b9 100644 (file)
@@ -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;
+    }
 }
index de3e45d..27e8a6e 100644 (file)
@@ -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]'));