[TASK] Drop usages of PATH_typo3, PATH_typo3conf 42/57242/11
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 20:06:42 +0000 (22:06 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 28 Jun 2018 07:38:22 +0000 (09:38 +0200)
After PATH_site usages have been dropped, this patch drops
the other path related constants PATH_typo3 and PATH_typo3conf.

Next steps (out of scope for this patch):
- Make typo3conf/l10n/ flexible (= var/labels)
- Move PackageStates and autoload/autoload-tests into typo3conf/ext/typo3/
- Analyze usages of "typo3conf" and "typo3/sysext" strings currently hardcoded

Change-Id: I4f0ca5dfab363fd3c14d030592318b9659721ecb
Resolves: #85286
Releases: master
Reviewed-on: https://review.typo3.org/57242
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
20 files changed:
typo3/sysext/backend/Classes/Command/LockBackendCommand.php
typo3/sysext/backend/Classes/Command/UnlockBackendCommand.php
typo3/sysext/backend/Classes/Controller/AjaxLoginController.php
typo3/sysext/backend/Classes/Http/Application.php
typo3/sysext/backend/Classes/Middleware/LockedBackendGuard.php
typo3/sysext/backend/Classes/Routing/UriBuilder.php
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/core/Classes/Core/Environment.php
typo3/sysext/core/Classes/Core/SystemEnvironmentBuilder.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-85285-DeprecatedSystemConstants.rst
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorIntegrationTest.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php
typo3/sysext/extensionmanager/Classes/Domain/Model/Extension.php
typo3/sysext/frontend/Classes/Http/Application.php
typo3/sysext/install/Classes/Controller/InstallerController.php
typo3/sysext/install/Classes/Http/RequestHandler.php
typo3/sysext/install/Configuration/ExtensionScanner/Php/ConstantMatcher.php
typo3/sysext/setup/Classes/Controller/SetupModuleController.php

index 918127d..553b89b 100644 (file)
@@ -18,6 +18,7 @@ use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -72,6 +73,6 @@ class LockBackendCommand extends Command
      */
     protected function getLockFileName()
     {
-        return PATH_typo3conf . 'LOCK_BACKEND';
+        return Environment::getLegacyConfigPath() . '/LOCK_BACKEND';
     }
 }
index b072d80..a7279b7 100644 (file)
@@ -17,6 +17,7 @@ use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Style\SymfonyStyle;
+use TYPO3\CMS\Core\Core\Environment;
 
 /**
  * Core function for unlocking the TYPO3 Backend
@@ -61,6 +62,6 @@ class UnlockBackendCommand extends Command
      */
     protected function getLockFileName()
     {
-        return PATH_typo3conf . 'LOCK_BACKEND';
+        return Environment::getLegacyConfigPath() . '/LOCK_BACKEND';
     }
 }
index 5f4e916..871547d 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Controller;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\Http\JsonResponse;
 
@@ -98,7 +99,7 @@ class AjaxLoginController
             'locked' => false
         ];
         $backendUser = $this->getBackendUser();
-        if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
+        if (@is_file(Environment::getLegacyConfigPath() . '/LOCK_BACKEND')) {
             $session['locked'] = true;
         } elseif (!isset($backendUser->user['uid'])) {
             $session['timed_out'] = true;
index 7c0791e..e61f0a7 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Configuration\ConfigurationManager;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Context\DateTimeAspect;
 use TYPO3\CMS\Core\Context\VisibilityAspect;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Http\AbstractApplication;
 use TYPO3\CMS\Core\Http\RedirectResponse;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -74,7 +75,8 @@ class Application extends AbstractApplication
      */
     protected function checkIfEssentialConfigurationExists(): bool
     {
-        return file_exists($this->configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
+        return file_exists($this->configurationManager->getLocalConfigurationFileLocation())
+            && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
     }
 
     /**
index 8c0cb82..9917ea9 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\RedirectResponse;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -64,8 +65,8 @@ class LockedBackendGuard implements MiddlewareInterface
         if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
             throw new \RuntimeException('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] . '".', 1517949794);
         }
-        if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
-            $fileContent = file_get_contents(PATH_typo3conf . 'LOCK_BACKEND');
+        if (@is_file(Environment::getLegacyConfigPath() . '/LOCK_BACKEND')) {
+            $fileContent = file_get_contents(Environment::getLegacyConfigPath() . '/LOCK_BACKEND');
             if ($fileContent) {
                 return $fileContent;
             }
index 10e998d..6808ce5 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Routing;
  */
 
 use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\Http\Uri;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -145,7 +146,7 @@ class UriBuilder
     {
         $uri = 'index.php?' . ltrim(GeneralUtility::implodeArrayForUrl('', $parameters, '', false, true), '&');
         if ($referenceType === self::ABSOLUTE_PATH) {
-            $uri = PathUtility::getAbsoluteWebPath(PATH_typo3 . $uri);
+            $uri = PathUtility::getAbsoluteWebPath(Environment::getBackendPath() . '/' . $uri);
         } else {
             $uri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_DIR') . $uri;
         }
index ebab07d..80a62ff 100644 (file)
@@ -375,7 +375,8 @@ class Bootstrap
             $configurationManager = new ConfigurationManager;
             static::$instance->setEarlyInstance(ConfigurationManager::class, $configurationManager);
         }
-        return file_exists($configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
+        return file_exists($configurationManager->getLocalConfigurationFileLocation())
+            && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
     }
 
     /**
index 4db7cdc..ee7227d 100644 (file)
@@ -185,6 +185,69 @@ class Environment
     }
 
     /**
+     * Helper methods to easily find occurrences, however as these properties are not computed
+     * it is very possible that these methods will become obsolete in the near future.
+     */
+
+    /**
+     * Previously found under typo3conf/l10n/
+     * Please note that this might be gone at some point
+     *
+     * @return string
+     */
+    public static function getLabelsPath(): string
+    {
+        if (self::$publicPath === self::$projectPath) {
+            return self::getPublicPath() . '/typo3conf/l10n';
+        }
+        return self::getVarPath() . '/labels';
+    }
+
+    /**
+     * Previously known as PATH_typo3
+     * Please note that this might be gone at some point
+     *
+     * @return string
+     */
+    public static function getBackendPath(): string
+    {
+        return self::getPublicPath() . '/typo3';
+    }
+
+    /**
+     * Previously known as PATH_typo3 . 'sysext/'
+     * Please note that this might be gone at some point
+     *
+     * @return string
+     */
+    public static function getFrameworkBasePath(): string
+    {
+        return self::getPublicPath() . '/typo3/sysext';
+    }
+
+    /**
+     * Previously known as PATH_site . 'typo3conf/ext/'
+     * Please note that this might be gone at some point
+     *
+     * @return string
+     */
+    public static function getExtensionsPath(): string
+    {
+        return self::getPublicPath() . '/typo3conf/ext';
+    }
+
+    /**
+     * Previously known as PATH_typo3conf
+     * Please note that this might be gone at some point
+     *
+     * @return string
+     */
+    public static function getLegacyConfigPath(): string
+    {
+        return self::getPublicPath() . '/typo3conf';
+    }
+
+    /**
      * Whether this TYPO3 installation runs on windows
      *
      * @return bool
index 6c56dfc..e2a5a48 100644 (file)
@@ -98,6 +98,11 @@ class SystemEnvironmentBuilder
      */
     protected static function defineBaseConstants()
     {
+        // Check one of the constants and return early if defined already
+        if (defined('TYPO3_version')) {
+            return;
+        }
+
         // This version, branch and copyright
         define('TYPO3_version', '9.4.0-dev');
         define('TYPO3_branch', '9.4');
@@ -198,13 +203,21 @@ class SystemEnvironmentBuilder
         }
         // Relative path from document root to typo3/ directory
         // Hardcoded to "typo3/"
-        define('TYPO3_mainDir', 'typo3/');
+        if (!defined('TYPO3_mainDir')) {
+            define('TYPO3_mainDir', 'typo3/');
+        }
         // Absolute path of the typo3 directory of the instance with trailing slash
         // Example "/var/www/instance-name/htdocs/typo3/"
-        define('PATH_typo3', PATH_site . TYPO3_mainDir);
+        if (!defined('PATH_typo3')) {
+            // @deprecated since v9, will be removed in v10
+            define('PATH_typo3', PATH_site . TYPO3_mainDir);
+        }
         // Absolute path to the typo3conf directory with trailing slash
         // Example "/var/www/instance-name/htdocs/typo3conf/"
-        define('PATH_typo3conf', PATH_site . 'typo3conf/');
+        if (!defined('PATH_typo3conf')) {
+            // @deprecated since v9, will be removed in v10
+            define('PATH_typo3conf', PATH_site . 'typo3conf/');
+        }
     }
 
     /**
index 534cc14..891af0e 100644 (file)
@@ -3440,16 +3440,16 @@ class GeneralUtility
             return str_replace($fileName, $language . '.' . $fileName, $fileRef);
         }
 
-        // Analyse file reference:
-        // Is system:
-        if (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) {
-            $validatedPrefix = PATH_typo3 . 'sysext/';
-        } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) {
-            // Is global:
-            $validatedPrefix = PATH_typo3 . 'ext/';
-        } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) {
-            // Is local:
-            $validatedPrefix = PATH_typo3conf . 'ext/';
+        // Analyse file reference
+        if (self::isFirstPartOfStr($fileRef, Environment::getFrameworkBasePath() . '/')) {
+            // Is system
+            $validatedPrefix = Environment::getFrameworkBasePath() . '/';
+        } elseif (self::isFirstPartOfStr($fileRef, Environment::getBackendPath() . '/ext/')) {
+            // Is global
+            $validatedPrefix = Environment::getBackendPath() . '/ext/';
+        } elseif (self::isFirstPartOfStr($fileRef, Environment::getExtensionsPath() . '/')) {
+            // Is local
+            $validatedPrefix = Environment::getExtensionsPath() . '/';
         } else {
             $validatedPrefix = '';
         }
index d00ec92..f45734c 100644 (file)
@@ -17,6 +17,12 @@ The following constants have been deprecated and should not be used any longer:
 * :php:`PATH_site`
   Use :php:`Environment::getPublicPath() . '/'` instead
 
+* :php:`PATH_typo3`
+  Use :php:`Environment::getPublicPath() . '/typo3/'` instead
+
+* :php:`PATH_typo3conf`
+  Use :php:`Environment::getPublicPath() . '/typo3conf'` instead
+
 
 Impact
 ======
index f7a4d6d..0ee19b4 100644 (file)
@@ -111,7 +111,7 @@ class ResourceCompressorIntegrationTest extends BaseTestCase
     {
         $testFile = Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
         $this->testFilesToDelete[] = $testFile;
-        copy(PATH_typo3 . $this->fixtureDir . 'css_input_with_import.css', $testFile);
+        copy(Environment::getBackendPath() . '/' . $this->fixtureDir . 'css_input_with_import.css', $testFile);
         $files = [
             'sampleFile1' => [
                 'excludeFromConcatenation' => false,
index f0ca838..7438ca0 100644 (file)
@@ -2284,8 +2284,7 @@ class GeneralUtilityTest extends UnitTestCase
      */
     public function getDirsReturnsArrayOfDirectoriesFromGivenDirectory()
     {
-        $path = PATH_typo3conf;
-        $directories = GeneralUtility::get_dirs($path);
+        $directories = GeneralUtility::get_dirs(Environment::getLegacyConfigPath() . '/');
         $this->assertInternalType(\PHPUnit\Framework\Constraint\IsType::TYPE_ARRAY, $directories);
     }
 
index e7acccc..48d5e5f 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Utility;
 
 use Prophecy\Argument;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
@@ -204,7 +205,7 @@ class LocalizationUtilityTest extends UnitTestCase
      */
     protected function getLanguageFilePath(string $extensionName): string
     {
-        return PATH_typo3 . 'sysext/' . $extensionName . '/Resources/Private/Language/locallang.xlf';
+        return Environment::getFrameworkBasePath() . '/' . $extensionName . '/Resources/Private/Language/locallang.xlf';
     }
 
     /**
index 091ddc1..a488657 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extensionmanager\Domain\Model;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+
 /**
  * Main extension model
  */
@@ -451,9 +453,9 @@ class Extension extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
     public static function returnInstallPaths()
     {
         $installPaths = [
-            'System' => PATH_typo3 . 'sysext/',
-            'Global' => PATH_typo3 . 'ext/',
-            'Local' => PATH_typo3conf . 'ext/'
+            'System' => Environment::getFrameworkBasePath() . '/',
+            'Global' => Environment::getBackendPath() . '/ext/',
+            'Local' => Environment::getExtensionsPath() . '/'
         ];
         return $installPaths;
     }
index 229122a..363e792 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Context\DateTimeAspect;
 use TYPO3\CMS\Core\Context\UserAspect;
 use TYPO3\CMS\Core\Context\VisibilityAspect;
 use TYPO3\CMS\Core\Context\WorkspaceAspect;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Http\AbstractApplication;
 use TYPO3\CMS\Core\Http\RedirectResponse;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -75,7 +76,8 @@ class Application extends AbstractApplication
      */
     protected function checkIfEssentialConfigurationExists(): bool
     {
-        return file_exists($this->configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
+        return file_exists($this->configurationManager->getLocalConfigurationFileLocation())
+            && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
     }
 
     /**
index 7e9ab09..60efa98 100644 (file)
@@ -108,7 +108,7 @@ class InstallerController
     public function checkEnvironmentAndFoldersAction(): ResponseInterface
     {
         return new JsonResponse([
-            'success' => @is_file(PATH_typo3conf . 'LocalConfiguration.php'),
+            'success' => @is_file(Environment::getLegacyConfigPath() . '/LocalConfiguration.php'),
         ]);
     }
 
@@ -153,12 +153,12 @@ class InstallerController
         $structureFixMessageQueue = $structureFacade->fix();
         $errorsFromStructure = $structureFixMessageQueue->getAllMessages(FlashMessage::ERROR);
 
-        if (@is_dir(PATH_typo3conf)) {
+        if (@is_dir(Environment::getLegacyConfigPath())) {
             $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
             $configurationManager->createLocalConfigurationFromFactoryConfiguration();
 
             // Create a PackageStates.php with all packages activated marked as "part of factory default"
-            if (!file_exists(PATH_typo3conf . 'PackageStates.php')) {
+            if (!file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php')) {
                 $packageManager = GeneralUtility::makeInstance(PackageManager::class);
                 $packages = $packageManager->getAvailablePackages();
                 foreach ($packages as $package) {
index 224cc93..3befc6b 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Install\Http;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\FormProtection\InstallToolFormProtection;
 use TYPO3\CMS\Core\Http\HtmlResponse;
@@ -306,6 +307,7 @@ class RequestHandler implements RequestHandlerInterface
      */
     protected function checkIfEssentialConfigurationExists(): bool
     {
-        return file_exists($this->configurationManager->getLocalConfigurationFileLocation()) && file_exists(PATH_typo3conf . 'PackageStates.php');
+        return file_exists($this->configurationManager->getLocalConfigurationFileLocation())
+            && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
     }
 }
index 3efef43..c16ac74 100644 (file)
@@ -71,4 +71,16 @@ return [
             'Deprecation-85285-DeprecatedSystemConstants.rst',
         ],
     ],
+    'PATH_typo3' => [
+        'restFiles' => [
+            'Feature-84153-IntroduceAGenericEnvironmentClass.rst',
+            'Deprecation-85285-DeprecatedSystemConstants.rst',
+        ],
+    ],
+    'PATH_typo3conf' => [
+        'restFiles' => [
+            'Feature-84153-IntroduceAGenericEnvironmentClass.rst',
+            'Deprecation-85285-DeprecatedSystemConstants.rst',
+        ],
+    ],
 ];
index c5e2dae..b112da3 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\DataHandling\DataHandler;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
@@ -668,7 +669,7 @@ class SetupModuleController
                     $localizedName = htmlspecialchars($name);
                 }
                 $localLabel = '  -  [' . htmlspecialchars($defaultName) . ']';
-                $available = is_dir(PATH_typo3conf . 'l10n/' . $locale);
+                $available = is_dir(Environment::getLegacyConfigPath() . '/l10n/' . $locale);
                 if ($available) {
                     $languageOptions[$defaultName] = '<option value="' . $locale . '"' . ($backendUser->uc['lang'] === $locale ? ' selected="selected"' : '') . '>' . $localizedName . $localLabel . '</option>';
                 }
@@ -678,7 +679,7 @@ class SetupModuleController
         $languageCode = '
             <select id="field_lang" name="data[lang]" class="form-control">' . implode('', $languageOptions) . '
             </select>';
-        if ($backendUser->uc['lang'] && !@is_dir(PATH_typo3conf . 'l10n/' . $backendUser->uc['lang'])) {
+        if ($backendUser->uc['lang'] && !@is_dir(Environment::getLegacyConfigPath() . '/l10n/' . $backendUser->uc['lang'])) {
             // TODO: The text constants have to be moved into language files
             $languageUnavailableWarning = 'The selected language "' . htmlspecialchars($language->getLL('lang_' . $backendUser->uc['lang'])) . '" is not available before the language files are installed.&nbsp;&nbsp;<br />&nbsp;&nbsp;' . ($backendUser->isAdmin() ? 'You can use the Language module to easily download new language files.' : 'Please ask your system administrator to do this.');
             $languageCode = '<br /><span class="label label-danger">' . $languageUnavailableWarning . '</span><br /><br />' . $languageCode;