[TASK] Rename RouteResult to SiteRouteResult 11/58511/2
authorBenni Mack <benni@typo3.org>
Sun, 30 Sep 2018 21:57:42 +0000 (23:57 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Sun, 30 Sep 2018 22:18:05 +0000 (00:18 +0200)
Resolves: #86489
Releases: master
Change-Id: I721c89b8afdc248b040a5e82cfd8c209dc84dbab
Reviewed-on: https://review.typo3.org/58511
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Classes/Routing/PageRouter.php
typo3/sysext/core/Classes/Routing/RouteResult.php [deleted file]
typo3/sysext/core/Classes/Routing/SiteMatcher.php
typo3/sysext/core/Classes/Routing/SiteRouteResult.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Routing/PageRouterTest.php
typo3/sysext/frontend/Classes/Middleware/PageResolver.php
typo3/sysext/frontend/Tests/Unit/Middleware/PageResolverTest.php

index 459b195..1313c2e 100644 (file)
@@ -104,8 +104,8 @@ class PageRouter implements RouterInterface
      * Finds a RouteResult based on the given request.
      *
      * @param ServerRequestInterface $request
-     * @param RouteResultInterface|RouteResult|null $previousResult
-     * @return RouteResult
+     * @param RouteResultInterface|SiteRouteResult|null $previousResult
+     * @return SiteRouteResult
      */
     public function matchRequest(ServerRequestInterface $request, RouteResultInterface $previousResult = null): ?RouteResultInterface
     {
diff --git a/typo3/sysext/core/Classes/Routing/RouteResult.php b/typo3/sysext/core/Classes/Routing/RouteResult.php
deleted file mode 100644 (file)
index 202c313..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Core\Routing;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use Psr\Http\Message\UriInterface;
-use TYPO3\CMS\Core\Site\Entity\SiteInterface;
-use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
-
-/**
- * Class, usually available within request attribute "routing"
- * containing all the findings of the Routers.
- *
- * @internal this API might change until 9 LTS.
- */
-class RouteResult implements RouteResultInterface
-{
-    /**
-     * @var array
-     */
-    protected $validProperties = ['uri', 'site', 'language', 'tail'];
-
-    /**
-     * Incoming URI which was processed.
-     * @var UriInterface
-     */
-    protected $uri;
-
-    /**
-     * @var SiteInterface
-     */
-    protected $site;
-
-    /**
-     * @var SiteLanguage
-     */
-    protected $language;
-
-    /**
-     * data bag with additional attributes
-     * @var array
-     */
-    protected $data;
-
-    /**
-     * The leftover string of the path from the uri
-     * @var string
-     */
-    protected $tail;
-
-    public function __construct(UriInterface $uri, SiteInterface $site, SiteLanguage $language = null, string $tail = '', array $data = [])
-    {
-        $this->uri = $uri;
-        $this->site = $site;
-        $this->language = $language;
-        $this->tail = $tail;
-        $this->data = $data;
-    }
-
-    public function getUri(): UriInterface
-    {
-        return $this->uri;
-    }
-
-    public function getSite(): SiteInterface
-    {
-        return $this->site;
-    }
-
-    public function getLanguage(): ?SiteLanguage
-    {
-        return $this->language;
-    }
-
-    public function getTail(): string
-    {
-        return $this->tail;
-    }
-
-    public function offsetExists($offset): bool
-    {
-        return in_array($offset, $this->validProperties, true) || isset($this->data[$offset]);
-    }
-
-    /**
-     * @param mixed $offset
-     * @return mixed|UriInterface|string|SiteInterface|SiteLanguage
-     */
-    public function offsetGet($offset)
-    {
-        switch ($offset) {
-            case 'uri':
-                return $this->uri;
-            case 'site':
-                return $this->site;
-            case 'language':
-                return $this->language;
-            case 'tail':
-                return $this->tail;
-            default:
-                return $this->data[$offset];
-        }
-    }
-
-    public function offsetSet($offset, $value)
-    {
-        switch ($offset) {
-            case 'uri':
-                throw new \InvalidArgumentException('You can never replace the URI in a route result', 1535462423);
-            case 'site':
-                throw new \InvalidArgumentException('You can never replace the Site object in a route result', 1535462454);
-            case 'language':
-                throw new \InvalidArgumentException('You can never replace the Language object in a route result', 1535462452);
-            case 'tail':
-                $this->tail = $value;
-                break;
-            default:
-                $this->data[$offset] = $value;
-        }
-    }
-
-    public function offsetUnset($offset)
-    {
-        switch ($offset) {
-            case 'uri':
-                throw new \InvalidArgumentException('You can never replace the URI in a route result', 1535462429);
-            case 'site':
-                throw new \InvalidArgumentException('You can never replace the Site object in a route result', 1535462458);
-            case 'language':
-                $this->language = null;
-                break;
-            case 'tail':
-                $this->tail = '';
-                break;
-            default:
-                unset($this->data[$offset]);
-        }
-    }
-}
index bed9bf8..a3d692b 100644 (file)
@@ -126,7 +126,7 @@ class SiteMatcher implements SingletonInterface
             $matcher = new UrlMatcher($collection, $context);
             try {
                 $result = $matcher->match($request->getUri()->getPath());
-                return new RouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
+                return new SiteRouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
             } catch (NoConfigurationException | ResourceNotFoundException $e) {
                 // No site+language combination found so far
             }
@@ -147,7 +147,7 @@ class SiteMatcher implements SingletonInterface
                 $context->setHost(implode('.', $host));
                 try {
                     $result = $matcher->match($request->getUri()->getPath());
-                    return new RouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
+                    return new SiteRouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
                 } catch (NoConfigurationException | ResourceNotFoundException $e) {
                     array_shift($host);
                 }
@@ -155,7 +155,7 @@ class SiteMatcher implements SingletonInterface
         } else {
             try {
                 $result = $matcher->match($request->getUri()->getPath());
-                return new RouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
+                return new SiteRouteResult($request->getUri(), $result['site'], $result['language'], $result['tail']);
             } catch (NoConfigurationException | ResourceNotFoundException $e) {
                 // No domain record found
             }
@@ -171,7 +171,7 @@ class SiteMatcher implements SingletonInterface
                 $site = reset($allPseudoSites);
             }
         }
-        return new RouteResult($request->getUri(), $site, $language);
+        return new SiteRouteResult($request->getUri(), $site, $language);
     }
 
     /**
diff --git a/typo3/sysext/core/Classes/Routing/SiteRouteResult.php b/typo3/sysext/core/Classes/Routing/SiteRouteResult.php
new file mode 100644 (file)
index 0000000..d0767b8
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Routing;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Psr\Http\Message\UriInterface;
+use TYPO3\CMS\Core\Site\Entity\SiteInterface;
+use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
+
+/**
+ * Class, usually available within request attribute "routing"
+ * containing all the findings of the Routers.
+ * When doing page-based routing the SiteRouteResult will get replaced with the PageArguments object.
+ */
+class SiteRouteResult implements RouteResultInterface
+{
+    /**
+     * @var array
+     */
+    protected $validProperties = ['uri', 'site', 'language', 'tail'];
+
+    /**
+     * Incoming URI which was processed.
+     * @var UriInterface
+     */
+    protected $uri;
+
+    /**
+     * @var SiteInterface
+     */
+    protected $site;
+
+    /**
+     * @var SiteLanguage
+     */
+    protected $language;
+
+    /**
+     * data bag with additional attributes
+     * @var array
+     */
+    protected $data;
+
+    /**
+     * The leftover string of the path from the uri
+     * @var string
+     */
+    protected $tail;
+
+    public function __construct(UriInterface $uri, SiteInterface $site, SiteLanguage $language = null, string $tail = '', array $data = [])
+    {
+        $this->uri = $uri;
+        $this->site = $site;
+        $this->language = $language;
+        $this->tail = $tail;
+        $this->data = $data;
+    }
+
+    public function getUri(): UriInterface
+    {
+        return $this->uri;
+    }
+
+    public function getSite(): SiteInterface
+    {
+        return $this->site;
+    }
+
+    public function getLanguage(): ?SiteLanguage
+    {
+        return $this->language;
+    }
+
+    public function getTail(): string
+    {
+        return $this->tail;
+    }
+
+    public function offsetExists($offset): bool
+    {
+        return in_array($offset, $this->validProperties, true) || isset($this->data[$offset]);
+    }
+
+    /**
+     * @param mixed $offset
+     * @return mixed|UriInterface|string|SiteInterface|SiteLanguage
+     */
+    public function offsetGet($offset)
+    {
+        switch ($offset) {
+            case 'uri':
+                return $this->uri;
+            case 'site':
+                return $this->site;
+            case 'language':
+                return $this->language;
+            case 'tail':
+                return $this->tail;
+            default:
+                return $this->data[$offset];
+        }
+    }
+
+    public function offsetSet($offset, $value)
+    {
+        switch ($offset) {
+            case 'uri':
+                throw new \InvalidArgumentException('You can never replace the URI in a route result', 1535462423);
+            case 'site':
+                throw new \InvalidArgumentException('You can never replace the Site object in a route result', 1535462454);
+            case 'language':
+                throw new \InvalidArgumentException('You can never replace the Language object in a route result', 1535462452);
+            case 'tail':
+                $this->tail = $value;
+                break;
+            default:
+                $this->data[$offset] = $value;
+        }
+    }
+
+    public function offsetUnset($offset)
+    {
+        switch ($offset) {
+            case 'uri':
+                throw new \InvalidArgumentException('You can never replace the URI in a route result', 1535462429);
+            case 'site':
+                throw new \InvalidArgumentException('You can never replace the Site object in a route result', 1535462458);
+            case 'language':
+                $this->language = null;
+                break;
+            case 'tail':
+                $this->tail = '';
+                break;
+            default:
+                unset($this->data[$offset]);
+        }
+    }
+}
index 2425330..eff8825 100644 (file)
@@ -19,7 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Routing;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\Routing\PageRouter;
-use TYPO3\CMS\Core\Routing\RouteResult;
+use TYPO3\CMS\Core\Routing\SiteRouteResult;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
@@ -51,7 +51,7 @@ class PageRouterTest extends UnitTestCase
         $language = $site->getDefaultLanguage();
 
         $request = new ServerRequest($incomingUrl, 'GET');
-        $previousResult = new RouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom');
+        $previousResult = new SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom');
         $subject = $this->getAccessibleMock(PageRouter::class, ['getCandidateSlugsFromRoutePath', 'getPagesFromDatabaseForCandidates'], [$site, []]);
         $subject->expects($this->once())->method('getCandidateSlugsFromRoutePath')->willReturn($slugCandidates);
         $subject->expects($this->once())->method('getPagesFromDatabaseForCandidates')->willReturn([$pageRecord]);
@@ -85,13 +85,13 @@ class PageRouterTest extends UnitTestCase
         ]);
         $language = $site->getDefaultLanguage();
         $request = new ServerRequest($incomingUrl, 'GET');
-        $previousResult = new RouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom/unknown-code/');
+        $previousResult = new SiteRouteResult($request->getUri(), $site, $language, '/mr-magpie/bloom/unknown-code/');
         $subject = $this->getAccessibleMock(PageRouter::class, ['getCandidateSlugsFromRoutePath', 'getPagesFromDatabaseForCandidates'], [$site, []]);
         $subject->expects($this->once())->method('getCandidateSlugsFromRoutePath')->willReturn($slugCandidates);
         $subject->expects($this->once())->method('getPagesFromDatabaseForCandidates')->willReturn([$pageRecord]);
         $routeResult = $subject->matchRequest($request, $previousResult);
 
-        $expectedRouteResult = new RouteResult($request->getUri(), $site, $language, 'unknown-code/', ['page' => $pageRecord]);
+        $expectedRouteResult = new SiteRouteResult($request->getUri(), $site, $language, 'unknown-code/', ['page' => $pageRecord]);
         $this->assertEquals($expectedRouteResult, $routeResult);
     }
 }
index 34018af..53a7088 100644 (file)
@@ -27,7 +27,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction;
 use TYPO3\CMS\Core\Routing\PageArguments;
-use TYPO3\CMS\Core\Routing\RouteResult;
+use TYPO3\CMS\Core\Routing\SiteRouteResult;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\CMS\Core\Site\Entity\SiteInterface;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
@@ -76,7 +76,7 @@ class PageResolver implements MiddlewareInterface
 
         // Resolve the page ID based on TYPO3's native routing functionality
         if ($hasSiteConfiguration) {
-            /** @var RouteResult $previousResult */
+            /** @var SiteRouteResult $previousResult */
             $previousResult = $request->getAttribute('routing', null);
             if (!$previousResult) {
                 return GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
index 47e5de6..bcb0f6c 100644 (file)
@@ -25,7 +25,7 @@ use TYPO3\CMS\Core\Http\NullResponse;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\Routing\PageRouter;
-use TYPO3\CMS\Core\Routing\RouteResult;
+use TYPO3\CMS\Core\Routing\SiteRouteResult;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\CMS\Core\Site\Entity\SiteInterface;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
@@ -111,7 +111,7 @@ class PageResolverTest extends UnitTestCase
         $request = new ServerRequest($incomingUrl, 'GET');
         $request = $request->withAttribute('site', $site);
         $request = $request->withAttribute('language', $language);
-        $request = $request->withAttribute('routing', new RouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom'));
+        $request = $request->withAttribute('routing', new SiteRouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom'));
         $expectedRouteResult = new PageArguments(13, []);
 
         $pageRouterMock = $this->getMockBuilder(PageRouter::class)->disableOriginalConstructor()->setMethods(['matchRequest'])->getMock();
@@ -153,7 +153,7 @@ class PageResolverTest extends UnitTestCase
         $request = new ServerRequest($incomingUrl, 'GET');
         $request = $request->withAttribute('site', $site);
         $request = $request->withAttribute('language', $language);
-        $request = $request->withAttribute('routing', new RouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom/'));
+        $request = $request->withAttribute('routing', new SiteRouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom/'));
 
         $expectedRouteResult = new PageArguments(13, []);
         $pageRouterMock = $this->getMockBuilder(PageRouter::class)->disableOriginalConstructor()->setMethods(['matchRequest'])->getMock();
@@ -193,7 +193,7 @@ class PageResolverTest extends UnitTestCase
         $request = new ServerRequest($incomingUrl, 'GET');
         $request = $request->withAttribute('site', $site);
         $request = $request->withAttribute('language', $language);
-        $request = $request->withAttribute('routing', new RouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom/'));
+        $request = $request->withAttribute('routing', new SiteRouteResult($request->getUri(), $site, $language, 'mr-magpie/bloom/'));
 
         $expectedRouteResult = new PageArguments(13, []);
         $pageRouterMock = $this->getMockBuilder(PageRouter::class)->disableOriginalConstructor()->setMethods(['matchRequest'])->getMock();