[TASK] Replace PATH_thisScript with Environment API call 19/56819/2
authorBenni Mack <benni@typo3.org>
Thu, 26 Apr 2018 16:46:01 +0000 (18:46 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 27 Apr 2018 19:40:48 +0000 (21:40 +0200)
All occurrences in the TYPO3 core have been replaced with
Environment::getCurrentScript() in order to slowly migrate
away from constants, and also detect dependencies to Environment
related functionality easier.

Resolves: #84883
Releases: master
Change-Id: I5197020bb539d9471cfa2aa3c7a09fa4b1a7d83c
Reviewed-on: https://review.typo3.org/56819
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/Http/NormalizedParams.php
typo3/sysext/core/Classes/Middleware/NormalizedParamsAttribute.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Classes/Utility/PathUtility.php

index af3b6fe..7cf227b 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Routing\UriBuilder;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
@@ -2974,7 +2975,7 @@ class BackendUtility
             $mainParams = ['id' => $mainParams];
         }
         if (!$script) {
-            $script = basename(PATH_thisScript);
+            $script = basename(Environment::getCurrentScript());
         }
 
         if ($routePath = GeneralUtility::_GP('route')) {
index 008da9f..b68bf1b 100644 (file)
@@ -287,7 +287,7 @@ class NormalizedParams
      *
      * @param ServerRequestInterface $serverRequest Used to access $_SERVER
      * @param array $typo3ConfVars $GLOBALS['TYPO3_CONF_VARS']
-     * @param string $pathThisScript Absolute server entry script path, constant PATH_thisScript
+     * @param string $pathThisScript Absolute server entry script path, usually found within Environment::getCurrentScript()
      * @param string $pathSite Absolute server path to document root, constant PATH_site
      */
     public function __construct(ServerRequestInterface $serverRequest, array $typo3ConfVars, string $pathThisScript, string $pathSite)
index 2a4eb5d..bdc95b1 100644 (file)
@@ -19,6 +19,7 @@ use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Server\MiddlewareInterface;
 use Psr\Http\Server\RequestHandlerInterface;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Http\NormalizedParams;
 
 /**
@@ -39,7 +40,7 @@ class NormalizedParamsAttribute implements MiddlewareInterface
      */
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
     {
-        $request = $request->withAttribute('normalizedParams', new NormalizedParams($request, $GLOBALS['TYPO3_CONF_VARS'], PATH_thisScript, PATH_site));
+        $request = $request->withAttribute('normalizedParams', new NormalizedParams($request, $GLOBALS['TYPO3_CONF_VARS'], Environment::getCurrentScript(), PATH_site));
 
         // Set $request as global variable. This is needed in a transition phase until core code has been
         // refactored to have ServerRequest object available where it is needed. This global will be
index baf9930..175394b 100644 (file)
@@ -2469,7 +2469,7 @@ class GeneralUtility
     public static function createVersionNumberedFilename($file)
     {
         $lookupFile = explode('?', $file);
-        $path = self::resolveBackPath(self::dirname(PATH_thisScript) . '/' . $lookupFile[0]);
+        $path = self::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $lookupFile[0]);
 
         $doNothing = false;
         if (TYPO3_MODE === 'FE') {
@@ -2637,7 +2637,7 @@ class GeneralUtility
                 }
                 break;
             case 'SCRIPT_FILENAME':
-                $retVal = PATH_thisScript;
+                $retVal = Environment::getCurrentScript();
                 break;
             case 'REQUEST_URI':
                 // Typical application of REQUEST_URI is return urls, forms submitting to itself etc. Example: returnUrl='.rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'))
@@ -2793,8 +2793,8 @@ class GeneralUtility
                 // This can only be set by external entry scripts
                 if (defined('TYPO3_PATH_WEB')) {
                     $retVal = $url;
-                } elseif (defined('PATH_thisScript') && defined('PATH_site')) {
-                    $lPath = PathUtility::stripPathSitePrefix(dirname(PATH_thisScript)) . '/';
+                } elseif (Environment::getCurrentScript() && defined('PATH_site')) {
+                    $lPath = PathUtility::stripPathSitePrefix(dirname(Environment::getCurrentScript())) . '/';
                     $siteUrl = substr($url, 0, -strlen($lPath));
                     if (substr($siteUrl, -1) !== '/') {
                         $siteUrl .= '/';
index 9d8a577..6f874cc 100644 (file)
@@ -30,7 +30,7 @@ class PathUtility
      */
     public static function getRelativePathTo($targetPath)
     {
-        return self::getRelativePath(dirname(PATH_thisScript), $targetPath);
+        return self::getRelativePath(dirname(Environment::getCurrentScript()), $targetPath);
     }
 
     /**
@@ -52,7 +52,7 @@ class PathUtility
             return $targetPath;
         } else {
             // Make an absolute path out of it
-            $targetPath = GeneralUtility::resolveBackPath(dirname(PATH_thisScript) . '/' . $targetPath);
+            $targetPath = GeneralUtility::resolveBackPath(dirname(Environment::getCurrentScript()) . '/' . $targetPath);
             $targetPath = self::stripPathSitePrefix($targetPath);
             if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI)) {
                 $targetPath = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . $targetPath;