[TASK] Move PageUriBuilder to EXT:core 84/57784/3
authorFrank Naegler <frank.naegler@typo3.org>
Thu, 2 Aug 2018 19:05:38 +0000 (21:05 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 2 Aug 2018 19:47:08 +0000 (21:47 +0200)
The class PageUriBuilder is moved to the system extension EXT:core

A class alias is in place.

Resolves: #85736
Releases: master
Change-Id: Ib96dda9cf30131fc86bc44a2cbc38ac4fc86f9ae
Reviewed-on: https://review.typo3.org/57784
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/backend/Classes/Routing/PageUriBuilder.php [deleted file]
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php
typo3/sysext/core/Classes/Routing/PageUriBuilder.php [new file with mode: 0644]
typo3/sysext/core/Migrations/Code/ClassAliasMap.php
typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php

diff --git a/typo3/sysext/backend/Classes/Routing/PageUriBuilder.php b/typo3/sysext/backend/Classes/Routing/PageUriBuilder.php
deleted file mode 100644 (file)
index b1242da..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-declare(strict_types = 1);
-
-namespace TYPO3\CMS\Backend\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\Exception\SiteNotFoundException;
-use TYPO3\CMS\Core\Http\Uri;
-use TYPO3\CMS\Core\SingletonInterface;
-use TYPO3\CMS\Core\Site\SiteFinder;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * Responsible for generates URLs to pages which are NOT bound to any permissions or frontend restrictions.
- *
- * If a page is built with a site in the root line, the base of the site (+ language) is used
- * and the &L parameter is then dropped explicitly.
- *
- * @internal as this might change until TYPO3 v9 LTS
- * @todo: check handling of MP parameter.
- */
-class PageUriBuilder implements SingletonInterface
-{
-    /**
-     * Generates an absolute URL
-     */
-    public const ABSOLUTE_URL = 'url';
-
-    /**
-     * Generates an absolute path
-     */
-    public const ABSOLUTE_PATH = 'path';
-
-    /**
-     * @var SiteFinder
-     */
-    protected $siteFinder;
-
-    /**
-     * PageUriBuilder constructor.
-     */
-    public function __construct()
-    {
-        $this->siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
-    }
-
-    /**
-     * Main entrypoint for generating an Uri for a page.
-     *
-     * @param int $pageId
-     * @param array $queryParameters
-     * @param string $fragment
-     * @param array $options ['language' => 123, 'rootLine' => etc.]
-     * @param string $referenceType
-     * @return UriInterface
-     */
-    public function buildUri(int $pageId, array $queryParameters = [], string $fragment = null, array $options = [], string $referenceType = self::ABSOLUTE_PATH): UriInterface
-    {
-        // Resolve site
-        $languageOption = isset($options['language']) ? (int)$options['language'] : null;
-        $languageQueryParameter = isset($queryParameters['L']) ? (int)$queryParameters['L'] : null;
-        $languageId = $languageOption ?? $languageQueryParameter ?? null;
-
-        // alternative page ID - Used to set as alias as well
-        $alternativePageId = $options['alternativePageId'] ?? $pageId;
-        $siteLanguage = null;
-        try {
-            $site = $this->siteFinder->getSiteByPageId($pageId, $options['rootLine'] ?? null);
-            if ($site) {
-                // Resolve language (based on the options / query parameters, and remove it from GET variables,
-                // as the language is determined by the language path
-                unset($queryParameters['L']);
-                $siteLanguage = $site->getLanguageById($languageId ?? 0);
-            }
-        } catch (SiteNotFoundException | \InvalidArgumentException $e) {
-        }
-
-        // If something is found, use /en/?id=123&additionalParams
-        // Only if a language is configured for the site, build a URL with a site prefix / base
-        if ($siteLanguage) {
-            unset($options['legacyUrlPrefix']);
-            $prefix = $siteLanguage->getBase() . '?id=' . $alternativePageId;
-        } else {
-            // If nothing is found, use index.php?id=123&additionalParams
-            $prefix = $options['legacyUrlPrefix'] ?? null;
-            if ($prefix === null) {
-                $prefix = $referenceType === self::ABSOLUTE_URL ? GeneralUtility::getIndpEnv('TYPO3_SITE_URL') : '';
-            }
-            $prefix .= 'index.php?id=' . $alternativePageId;
-            if ($languageId !== null) {
-                $queryParameters['L'] = $languageId;
-            }
-        }
-
-        // Add the query parameters as string
-        $queryString = http_build_query($queryParameters, '', '&', PHP_QUERY_RFC3986);
-        $uri = new Uri($prefix . ($queryString ? '&' . $queryString : ''));
-        if ($fragment) {
-            $uri = $uri->withFragment($fragment);
-        }
-        if ($referenceType === self::ABSOLUTE_PATH && !isset($options['legacyUrlPrefix'])) {
-            $uri = $uri->withScheme('')->withHost('')->withPort(null);
-        }
-        return $uri;
-    }
-}
index 97210c1..a418fb8 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Backend\Utility;
 
 use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository;
-use TYPO3\CMS\Backend\Routing\PageUriBuilder;
 use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
@@ -41,6 +40,7 @@ use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
+use TYPO3\CMS\Core\Routing\PageUriBuilder;
 use TYPO3\CMS\Core\Site\SiteFinder;
 use TYPO3\CMS\Core\Type\Bitmask\Permission;
 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
index c689003..ae236b7 100644 (file)
@@ -18,9 +18,9 @@ namespace TYPO3\CMS\Core\Error\PageErrorHandler;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Backend\Routing\PageUriBuilder;
 use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\LinkHandling\LinkService;
+use TYPO3\CMS\Core\Routing\PageUriBuilder;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
diff --git a/typo3/sysext/core/Classes/Routing/PageUriBuilder.php b/typo3/sysext/core/Classes/Routing/PageUriBuilder.php
new file mode 100644 (file)
index 0000000..9e3e024
--- /dev/null
@@ -0,0 +1,119 @@
+<?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\Exception\SiteNotFoundException;
+use TYPO3\CMS\Core\Http\Uri;
+use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Site\SiteFinder;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Responsible for generates URLs to pages which are NOT bound to any permissions or frontend restrictions.
+ *
+ * If a page is built with a site in the root line, the base of the site (+ language) is used
+ * and the &L parameter is then dropped explicitly.
+ *
+ * @internal as this might change until TYPO3 v9 LTS
+ * @todo: check handling of MP parameter.
+ */
+class PageUriBuilder implements SingletonInterface
+{
+    /**
+     * Generates an absolute URL
+     */
+    public const ABSOLUTE_URL = 'url';
+
+    /**
+     * Generates an absolute path
+     */
+    public const ABSOLUTE_PATH = 'path';
+
+    /**
+     * @var SiteFinder
+     */
+    protected $siteFinder;
+
+    /**
+     * PageUriBuilder constructor.
+     */
+    public function __construct()
+    {
+        $this->siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
+    }
+
+    /**
+     * Main entrypoint for generating an Uri for a page.
+     *
+     * @param int $pageId
+     * @param array $queryParameters
+     * @param string $fragment
+     * @param array $options ['language' => 123, 'rootLine' => etc.]
+     * @param string $referenceType
+     * @return UriInterface
+     */
+    public function buildUri(int $pageId, array $queryParameters = [], string $fragment = null, array $options = [], string $referenceType = self::ABSOLUTE_PATH): UriInterface
+    {
+        // Resolve site
+        $languageOption = isset($options['language']) ? (int)$options['language'] : null;
+        $languageQueryParameter = isset($queryParameters['L']) ? (int)$queryParameters['L'] : null;
+        $languageId = $languageOption ?? $languageQueryParameter ?? null;
+
+        // alternative page ID - Used to set as alias as well
+        $alternativePageId = $options['alternativePageId'] ?? $pageId;
+        $siteLanguage = null;
+        try {
+            $site = $this->siteFinder->getSiteByPageId($pageId, $options['rootLine'] ?? null);
+            if ($site) {
+                // Resolve language (based on the options / query parameters, and remove it from GET variables,
+                // as the language is determined by the language path
+                unset($queryParameters['L']);
+                $siteLanguage = $site->getLanguageById($languageId ?? 0);
+            }
+        } catch (SiteNotFoundException | \InvalidArgumentException $e) {
+        }
+
+        // If something is found, use /en/?id=123&additionalParams
+        // Only if a language is configured for the site, build a URL with a site prefix / base
+        if ($siteLanguage) {
+            unset($options['legacyUrlPrefix']);
+            $prefix = $siteLanguage->getBase() . '?id=' . $alternativePageId;
+        } else {
+            // If nothing is found, use index.php?id=123&additionalParams
+            $prefix = $options['legacyUrlPrefix'] ?? null;
+            if ($prefix === null) {
+                $prefix = $referenceType === self::ABSOLUTE_URL ? GeneralUtility::getIndpEnv('TYPO3_SITE_URL') : '';
+            }
+            $prefix .= 'index.php?id=' . $alternativePageId;
+            if ($languageId !== null) {
+                $queryParameters['L'] = $languageId;
+            }
+        }
+
+        // Add the query parameters as string
+        $queryString = http_build_query($queryParameters, '', '&', PHP_QUERY_RFC3986);
+        $uri = new Uri($prefix . ($queryString ? '&' . $queryString : ''));
+        if ($fragment) {
+            $uri = $uri->withFragment($fragment);
+        }
+        if ($referenceType === self::ABSOLUTE_PATH && !isset($options['legacyUrlPrefix'])) {
+            $uri = $uri->withScheme('')->withHost('')->withPort(null);
+        }
+        return $uri;
+    }
+}
index f25bf93..2582136 100644 (file)
@@ -5,5 +5,6 @@ return [
     'TYPO3\\CMS\\Sv\\AbstractAuthenticationService' => \TYPO3\CMS\Core\Authentication\AbstractAuthenticationService::class,
     'TYPO3\\CMS\\Sv\\AuthenticationService' => \TYPO3\CMS\Core\Authentication\AuthenticationService::class,
     'TYPO3\\CMS\\Core\\Tree\\TableConfiguration\\ExtJsArrayTreeRenderer' => \TYPO3\CMS\Core\Tree\TableConfiguration\ArrayTreeRenderer::class,
-    'TYPO3\\CMS\\Core\\History\\RecordHistory' => \TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore::class
+    'TYPO3\\CMS\\Core\\History\\RecordHistory' => \TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore::class,
+    'TYPO3\\CMS\\Backend\\Routing\\PageUriBuilder' => \TYPO3\CMS\Core\Routing\PageUriBuilder::class,
 ];
index 1399019..8fdfe05 100644 (file)
@@ -16,11 +16,11 @@ namespace TYPO3\CMS\Frontend\Typolink;
  */
 
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Backend\Routing\PageUriBuilder;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Exception\Page\RootLineException;
+use TYPO3\CMS\Core\Routing\PageUriBuilder;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;