diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e0a4943fcd..2d84aefdf8 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -22,12 +22,13 @@ * - If a site managed to bypass all of the above, then an error is shown in * the status report and various fatal errors occur on various pages. * - * @see install.php + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_PHP instead. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @see https://www.drupal.org/node/2909361 + * @see install.php */ -const DRUPAL_MINIMUM_PHP = '7.3.0'; +const DRUPAL_MINIMUM_PHP = \Drupal::MINIMUM_PHP; /** * Minimum supported version of PHP. @@ -38,10 +39,12 @@ * that Drupal no longer supports that PHP version. * - An error is shown in the status report that the PHP version is too old. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_SUPPORTED_PHP instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_MINIMUM_SUPPORTED_PHP = '7.3.0'; +const DRUPAL_MINIMUM_SUPPORTED_PHP = \Drupal::MINIMUM_SUPPORTED_PHP; /** * Minimum recommended version of PHP. @@ -50,10 +53,12 @@ * message, but Drupal can still be installed. Used for (e.g.) PHP versions * that have reached their EOL or will in the near future. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::RECOMMENDED_PHP instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_RECOMMENDED_PHP = '7.3'; +const DRUPAL_RECOMMENDED_PHP = \Drupal::RECOMMENDED_PHP; /** * Minimum recommended value of PHP memory_limit. @@ -62,10 +67,12 @@ * contributed modules to be installed prior to hitting the limit. However, * 40M is the target for the Standard installation profile. * - * @todo Move this to an appropriate autoloadable class. See - * https://www.drupal.org/project/drupal/issues/2908079 + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * \Drupal::MINIMUM_PHP_MEMORY_LIMIT instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M'; +const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = \Drupal::MINIMUM_PHP_MEMORY_LIMIT; /** * Error reporting level: display no errors. diff --git a/core/includes/install.inc b/core/includes/install.inc index e806a09a41..7e79c0c11f 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -1078,7 +1078,7 @@ function install_profile_info($profile, $langcode = 'en') { 'description' => '', 'version' => NULL, 'hidden' => FALSE, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, 'config_install_path' => NULL, ]; $profile_path = drupal_get_path('profile', $profile); diff --git a/core/install.php b/core/install.php index 8fae042ed9..9bd0760e9b 100644 --- a/core/install.php +++ b/core/install.php @@ -21,17 +21,19 @@ */ define('MAINTENANCE_MODE', 'install'); -// Exit early if running an incompatible PHP version to avoid fatal errors. -// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not -// yet available. It is defined in bootstrap.inc, but it is not possible to -// load that file yet as it would cause a fatal error on older versions of PHP. +// Exit early if running an incompatible PHP version to avoid fatal errors. The +// minimum version is specified explicitly, as \Drupal::MINIMUM_PHP is not yet +// available. It is defined in core/lib/Drupal.php and it is not possible to +// load that file yet because namespaces weren't supported until PHP 5.3, on PHP +// 5.2 and earlier, the installer would whitescreen with a fatal error without +// explanation. if (version_compare(PHP_VERSION, '7.3.0') < 0) { - print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the system requirements page for more information.'; + print 'Your PHP installation is too old. Drupal requires at least PHP 7.3.0. See the Environment requirements of Drupal 9 page for more information.'; exit; } // Initialize the autoloader. -$class_loader = require_once $root_path . '/autoload.php'; +$autoloader = require_once $root_path . '/autoload.php'; // If OPCache is in use, ensure opcache.save_comments is enabled. if (OpCodeCache::isEnabled() && !ini_get('opcache.save_comments')) { @@ -41,4 +43,4 @@ // Start the installer. require_once $root_path . '/core/includes/install.core.inc'; -install_drupal($class_loader); +install_drupal($autoloader); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 461fda8547..34dd9b5307 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -92,6 +92,47 @@ class Drupal { */ const CORE_MINIMUM_SCHEMA_VERSION = 8000; + /** + * Minimum supported version of PHP. + * + * Below this version: + * - New sites cannot be installed, except from within tests. + * - Updates from previous Drupal versions can be run, but users are warned + * that Drupal no longer supports that PHP version. + * - An error is shown in the status report that the PHP version is too old. + */ + const MINIMUM_SUPPORTED_PHP = '7.3.0'; + + /** + * Minimum allowed version of PHP. + * + * Below this version: + * - The installer cannot be run. + * - Updates cannot be run. + * - Modules and themes cannot be enabled. + * - If a site managed to bypass all of the above, then an error is shown in + * the status report and various fatal errors occur on various pages. + */ + const MINIMUM_PHP = '7.3.0'; + + /** + * Minimum recommended value of PHP memory_limit. + * + * 64M was chosen as a minimum requirement in order to allow for additional + * contributed modules to be installed prior to hitting the limit. However, + * 40M is the target for the Standard installation profile. + */ + const MINIMUM_PHP_MEMORY_LIMIT = '64M'; + + /** + * Minimum recommended version of PHP. + * + * Sites installing Drupal on PHP versions lower than this will see a warning + * message, but Drupal can still be installed. Used for (e.g.) PHP versions + * that have reached their EOL or will in the near future. + */ + const RECOMMENDED_PHP = '7.3'; + /** * The currently active container object, or NULL if not initialized yet. * diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 60b08cc8b5..c05d892b24 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -28,7 +28,7 @@ class ModuleExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php index 7c415168d8..5ef9c451fd 100644 --- a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php @@ -22,7 +22,7 @@ class ProfileExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php index c4d39ef600..5b9bd692ef 100644 --- a/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ThemeEngineExtensionList.php @@ -21,7 +21,7 @@ class ThemeEngineExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php index e062793b81..e100a0e8b7 100644 --- a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php @@ -47,7 +47,7 @@ class ThemeExtensionList extends ExtensionList { 'comment_user_verification', ], 'screenshot' => 'screenshot.png', - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => \Drupal::MINIMUM_PHP, 'libraries' => [], 'libraries_extend' => [], 'libraries_override' => [], diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index e2ffe1320b..1e4f4b12cd 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -987,8 +987,8 @@ function hook_requirements($phase) { 'title' => t('PHP'), 'value' => ($phase == 'runtime') ? Link::fromTextAndUrl(phpversion(), Url::fromRoute('system.php'))->toString() : phpversion(), ]; - if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { - $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => DRUPAL_MINIMUM_PHP]); + if (version_compare(phpversion(), \Drupal::MINIMUM_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => \Drupal::MINIMUM_PHP]); $requirements['php']['severity'] = REQUIREMENT_ERROR; } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 89335d0136..0372ad3d70 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -202,19 +202,19 @@ function system_requirements($phase) { } // Check if the PHP version is below what Drupal supports. - if (version_compare($phpversion, DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { - $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See PHP\'s version support documentation and the Drupal 8 PHP requirements handbook page for more information.', + if (version_compare($phpversion, \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version. It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See PHP\'s version support documentation and the Environment requirements of Drupal 9 page for more information.', [ - '%version' => DRUPAL_MINIMUM_SUPPORTED_PHP, - '%recommended' => DRUPAL_RECOMMENDED_PHP, - ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php', + '%version' => \Drupal::MINIMUM_SUPPORTED_PHP, + '%recommended' => \Drupal::RECOMMENDED_PHP, + ':php_requirements' => 'https://www.drupal.org/docs/9/how-drupal-9-is-made-and-what-is-included/environment-requirements-of-drupal-9#s-php-version-requirement', ] ); $requirements['php']['severity'] = REQUIREMENT_ERROR; // If the PHP version is also below the absolute minimum allowed, it's not // safe to continue with the requirements check. - if (version_compare($phpversion, DRUPAL_MINIMUM_PHP) < 0) { + if (version_compare($phpversion, \Drupal::MINIMUM_PHP) < 0) { return $requirements; } // Otherwise downgrade the error to a warning during updates. Even if there @@ -235,8 +235,8 @@ function system_requirements($phase) { // For PHP versions that are still supported but no longer recommended, // inform users of what's recommended, allowing them to take action before it // becomes urgent. - elseif ($phase === 'runtime' && version_compare($phpversion, DRUPAL_RECOMMENDED_PHP) < 0) { - $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See PHP\'s version support documentation and the Drupal 8 PHP requirements handbook page for more information.', ['%recommended' => DRUPAL_RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']); + elseif ($phase === 'runtime' && version_compare($phpversion, \Drupal::RECOMMENDED_PHP) < 0) { + $requirements['php']['description'] = t('It is recommended to upgrade to PHP version %recommended or higher for the best ongoing support. See PHP\'s version support documentation and the Drupal 8 PHP requirements handbook page for more information.', ['%recommended' => \Drupal::RECOMMENDED_PHP, ':php_requirements' => 'https://www.drupal.org/docs/8/system-requirements/php']); $requirements['php']['severity'] = REQUIREMENT_INFO; } @@ -448,16 +448,16 @@ function system_requirements($phase) { 'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit, ]; - if (!Environment::checkMemoryLimit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) { + if (!Environment::checkMemoryLimit(\Drupal::MINIMUM_PHP_MEMORY_LIMIT, $memory_limit)) { $description = []; if ($phase == 'install') { - $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } elseif ($phase == 'update') { - $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the update process.', ['%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } elseif ($phase == 'runtime') { - $description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT]); + $description['phase'] = t('Depending on your configuration, Drupal can run with a %memory_limit PHP memory limit. However, a %memory_minimum_limit PHP memory limit or above is recommended, especially if your site uses additional custom or contributed modules.', ['%memory_limit' => $memory_limit, '%memory_minimum_limit' => \Drupal::MINIMUM_PHP_MEMORY_LIMIT]); } if (!empty($description['phase'])) { diff --git a/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php b/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php index a347200ad8..dab1ef3db0 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibrariesDirectoryFileFinderTest.php @@ -82,7 +82,3 @@ public function testFind() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.0.8'); -} diff --git a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php index 12a0d88e1c..fae9dd4d49 100644 --- a/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php +++ b/core/tests/Drupal/Tests/Core/Command/QuickStartTest.php @@ -86,7 +86,7 @@ public function tearDown(): void { * Tests the quick-start command. */ public function testQuickStartCommand() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->markTestSkipped(); } if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { @@ -144,7 +144,7 @@ public function testQuickStartCommand() { * Tests that the installer throws a requirement error on older PHP versions. */ public function testPhpRequirement() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) >= 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) >= 0) { $this->markTestSkipped(); } @@ -167,7 +167,7 @@ public function testPhpRequirement() { $error_output = $process->getErrorOutput(); $this->assertStringContainsString('Your PHP installation is too old.', $error_output); $this->assertStringContainsString('Drupal requires at least PHP', $error_output); - $this->assertStringContainsString(DRUPAL_MINIMUM_SUPPORTED_PHP, $error_output); + $this->assertContains(\Drupal::MINIMUM_SUPPORTED_PHP, $error_output); // Stop the web server. $process->stop(); @@ -177,7 +177,7 @@ public function testPhpRequirement() { * Tests the quick-start commands. */ public function testQuickStartInstallAndServerCommands() { - if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if (version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->markTestSkipped(); } if (version_compare(\SQLite3::version()['versionString'], Tasks::SQLITE_MINIMUM_VERSION) < 0) { diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php index 254bde86d6..3c2eb03d52 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleRequiredByThemesUninstallValidatorTest.php @@ -155,7 +155,3 @@ public function testValidateTwoThemeDependencies() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php index a4085b0f8e..835dc94b59 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeExtensionListTest.php @@ -259,7 +259,3 @@ class TestThemeEngineExtensionList extends ThemeEngineExtensionList { use SettableDiscoveryExtensionListTrait; } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index b68765a877..fe2ca19033 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -145,7 +145,3 @@ protected function themeRegistryRebuild() { } } - -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '7.3.0'); -} diff --git a/core/tests/Drupal/Tests/RequirementsPageTrait.php b/core/tests/Drupal/Tests/RequirementsPageTrait.php index b71afba084..0c2cc2a114 100644 --- a/core/tests/Drupal/Tests/RequirementsPageTrait.php +++ b/core/tests/Drupal/Tests/RequirementsPageTrait.php @@ -13,7 +13,7 @@ trait RequirementsPageTrait { protected function updateRequirementsProblem() { // Assert a warning is shown on older test environments. $links = $this->getSession()->getPage()->findAll('named', ['link', 'try again']); - if ($links && version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) { + if ($links && version_compare(phpversion(), \Drupal::MINIMUM_SUPPORTED_PHP) < 0) { $this->assertNoText('Errors found'); $this->assertWarningSummaries(['PHP']); $this->clickLink('try again');