Commit d15b46b9 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[!!!][TASK] Remove constants TYPO3_MODE and TYPO3_REQUESTTYPE

Resolves: #96196
Related: #92947
Releases: main
Change-Id: I9f8e9949c5443eb0324b8406346f98e87bfacc20
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72456

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 529661be
...@@ -189,14 +189,10 @@ class Bootstrap ...@@ -189,14 +189,10 @@ class Bootstrap
* *
* Script execution will be aborted if something fails here. * Script execution will be aborted if something fails here.
* *
* @throws \RuntimeException when TYPO3_REQUESTTYPE was not set before, setRequestType() needs to be called before
* @internal This is not a public API method, do not use in own extensions * @internal This is not a public API method, do not use in own extensions
*/ */
public static function baseSetup() public static function baseSetup()
{ {
if (!defined('TYPO3_REQUESTTYPE')) {
throw new \RuntimeException('No Request Type was set, TYPO3 does not know in which context it is run.', 1450561838);
}
if (!Environment::isComposerMode() && ClassLoadingInformation::isClassLoadingInformationAvailable()) { if (!Environment::isComposerMode() && ClassLoadingInformation::isClassLoadingInformationAvailable()) {
ClassLoadingInformation::registerClassLoadingInformation(); ClassLoadingInformation::registerClassLoadingInformation();
} }
......
...@@ -35,9 +35,7 @@ use TYPO3\CMS\Core\Utility\PathUtility; ...@@ -35,9 +35,7 @@ use TYPO3\CMS\Core\Utility\PathUtility;
* This class only defines what is configured through the environment, does not do any checks if paths exist * This class only defines what is configured through the environment, does not do any checks if paths exist
* etc. This should be part of the application or the SystemEnvironmentBuilder. * etc. This should be part of the application or the SystemEnvironmentBuilder.
* *
* In your application, use it like this: * In your application, use it like this: "Environment::isCli()"
*
* Instead of writing "TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI" call "Environment::isCli()"
*/ */
class Environment class Environment
{ {
......
...@@ -61,9 +61,6 @@ class SystemEnvironmentBuilder ...@@ -61,9 +61,6 @@ class SystemEnvironmentBuilder
public static function run(int $entryPointLevel = 0, int $requestType = self::REQUESTTYPE_FE) public static function run(int $entryPointLevel = 0, int $requestType = self::REQUESTTYPE_FE)
{ {
self::defineBaseConstants(); self::defineBaseConstants();
self::defineTypo3RequestTypes();
self::setRequestType($requestType | ($requestType === self::REQUESTTYPE_BE && (str_contains($_SERVER['REQUEST_URI'] ?? '', '/typo3/ajax/') || strpos($_REQUEST['route'] ?? '', '/ajax/') === 0) ? TYPO3_REQUESTTYPE_AJAX : 0));
self::defineLegacyConstants($requestType === self::REQUESTTYPE_FE ? 'FE' : 'BE');
$scriptPath = self::calculateScriptPath($entryPointLevel, $requestType); $scriptPath = self::calculateScriptPath($entryPointLevel, $requestType);
$rootPath = self::calculateRootPath($entryPointLevel, $requestType); $rootPath = self::calculateRootPath($entryPointLevel, $requestType);
...@@ -342,65 +339,6 @@ class SystemEnvironmentBuilder ...@@ -342,65 +339,6 @@ class SystemEnvironmentBuilder
return defined('TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE; return defined('TYPO3_COMPOSER_MODE') && TYPO3_COMPOSER_MODE;
} }
/**
* Define TYPO3_REQUESTTYPE* constants that can be used for developers to see if any context has been hit
* also see setRequestType(). Is done at the very beginning so these parameters are always available.
*
* @deprecated since v11, method can be removed in v12
*/
protected static function defineTypo3RequestTypes()
{
// Check one of the constants and return early if already defined,
// needed if multiple requests are handled in one process, for instance in functional testing.
if (defined('TYPO3_REQUESTTYPE_FE')) {
return;
}
/** @deprecated since v11, will be removed in v12. */
define('TYPO3_REQUESTTYPE_FE', self::REQUESTTYPE_FE);
/** @deprecated since v11, will be removed in v12. */
define('TYPO3_REQUESTTYPE_BE', self::REQUESTTYPE_BE);
/** @deprecated since v11, will be removed in v12. */
define('TYPO3_REQUESTTYPE_CLI', self::REQUESTTYPE_CLI);
/** @deprecated since v11, will be removed in v12. */
define('TYPO3_REQUESTTYPE_AJAX', self::REQUESTTYPE_AJAX);
/** @deprecated since v11, will be removed in v12. */
define('TYPO3_REQUESTTYPE_INSTALL', self::REQUESTTYPE_INSTALL);
}
/**
* Defines the TYPO3_REQUESTTYPE constant so the environment knows which context the request is running.
*
* @param int $requestType
* @deprecated since v11, method can be removed in v12
*/
protected static function setRequestType(int $requestType)
{
// Return early if already defined,
// needed if multiple requests are handled in one process, for instance in functional testing.
if (defined('TYPO3_REQUESTTYPE')) {
return;
}
/** @deprecated since v11, will be removed in v12. Use Core\Http\ApplicationType API or $request->getAttribute('applicationType') instead */
define('TYPO3_REQUESTTYPE', $requestType);
}
/**
* Define constants and variables
*
* @param string $mode
* @deprecated since v11, method can be removed in v12
*/
protected static function defineLegacyConstants(string $mode)
{
// Return early if already defined,
// needed if multiple requests are handled in one process, for instance in functional testing.
if (defined('TYPO3_MODE')) {
return;
}
/** @deprecated since v11, will be removed in v12. Use Core\Http\ApplicationType API instead */
define('TYPO3_MODE', $mode);
}
/** /**
* Checks if request type is cli. * Checks if request type is cli.
* Falls back to check PHP_SAPI in case request type is not provided * Falls back to check PHP_SAPI in case request type is not provided
......
...@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\FormProtection; ...@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\FormProtection;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue; use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
...@@ -109,7 +110,7 @@ class FormProtectionFactory ...@@ -109,7 +110,7 @@ class FormProtectionFactory
$isAjaxCall = false; $isAjaxCall = false;
$request = $GLOBALS['TYPO3_REQUEST'] ?? null; $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request instanceof ServerRequestInterface if ($request instanceof ServerRequestInterface
&& (bool)((int)$request->getAttribute('applicationType') & TYPO3_REQUESTTYPE_AJAX) && (bool)((int)$request->getAttribute('applicationType') & SystemEnvironmentBuilder::REQUESTTYPE_AJAX)
) { ) {
$isAjaxCall = true; $isAjaxCall = true;
} }
...@@ -142,7 +143,7 @@ class FormProtectionFactory ...@@ -142,7 +143,7 @@ class FormProtectionFactory
$isInstallTool = false; $isInstallTool = false;
$request = $GLOBALS['TYPO3_REQUEST'] ?? null; $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request instanceof ServerRequestInterface if ($request instanceof ServerRequestInterface
&& (bool)((int)$request->getAttribute('applicationType') & TYPO3_REQUESTTYPE_INSTALL) && (bool)((int)$request->getAttribute('applicationType') & SystemEnvironmentBuilder::REQUESTTYPE_INSTALL)
) { ) {
$isInstallTool = true; $isInstallTool = true;
} }
......
...@@ -242,36 +242,43 @@ return [ ...@@ -242,36 +242,43 @@ return [
'TYPO3_MODE' => [ 'TYPO3_MODE' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE' => [ 'TYPO3_REQUESTTYPE' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE_FE' => [ 'TYPO3_REQUESTTYPE_FE' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE_BE' => [ 'TYPO3_REQUESTTYPE_BE' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE_CLI' => [ 'TYPO3_REQUESTTYPE_CLI' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE_AJAX' => [ 'TYPO3_REQUESTTYPE_AJAX' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
'TYPO3_REQUESTTYPE_INSTALL' => [ 'TYPO3_REQUESTTYPE_INSTALL' => [
'restFiles' => [ 'restFiles' => [
'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst', 'Deprecation-92947-DeprecateTYPO3_MODEAndTYPO3_REQUESTTYPEConstants.rst',
'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
], ],
], ],
]; ];
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment