diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index a67d7ff654..ff85bd354c 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -10,6 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\BootstrapConfigStorageFactory; +use Drupal\Core\Requirements; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Test\TestDatabase; use Drupal\Core\Session\AccountInterface; @@ -20,9 +21,12 @@ /** * Minimum supported version of PHP. * - * Drupal cannot be installed on versions of PHP older than this version. + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Requirements::MINIMUM_PHP instead. + * + * @see https://www.drupal.org/node/2909361 */ -const DRUPAL_MINIMUM_PHP = '5.5.9'; +const DRUPAL_MINIMUM_PHP = Requirements::MINIMUM_PHP; /** * Minimum recommended version of PHP. @@ -39,8 +43,13 @@ * 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. + * + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Requirements::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 = Requirements::MINIMUM_PHP_MEMORY_LIMIT; /** * Error reporting level: display no errors. diff --git a/core/includes/install.inc b/core/includes/install.inc index 399476f102..6db739a7af 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -11,6 +11,7 @@ use Drupal\Component\Utility\OpCodeCache; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Extension\ExtensionDiscovery; +use Drupal\Core\Requirements; use Drupal\Core\Site\Settings; /** @@ -1089,7 +1090,7 @@ function install_profile_info($profile, $langcode = 'en') { 'description' => '', 'version' => NULL, 'hidden' => FALSE, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => Requirements::MINIMUM_PHP, ]; $profile_file = drupal_get_path('profile', $profile) . "/$profile.info.yml"; $info = \Drupal::service('info_parser')->parse($profile_file); diff --git a/core/install.php b/core/install.php index c88ffeedaa..2d8634c735 100644 --- a/core/install.php +++ b/core/install.php @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\OpCodeCache; +use Drupal\Core\Requirements; // Change the directory to the Drupal root. chdir('..'); @@ -21,11 +22,10 @@ */ 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. -if (version_compare(PHP_VERSION, '5.5.9') < 0) { +// Checking minimum PHP version to avoid fatal errors. +// The minimum version is specified in the Drupal\Core\Requirements class. +require_once $root_path . '/core/lib/Drupal/Core/Requirements.php'; +if (version_compare(PHP_VERSION, Requirements::MINIMUM_PHP) < 0) { print 'Your PHP installation is too old. Drupal requires at least PHP 5.5.9. See the system requirements page for more information.'; exit; } diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 01fcf59095..4db156b591 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -4,6 +4,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Requirements; use Drupal\Core\State\StateInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -22,7 +23,7 @@ class ModuleExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => Requirements::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php index bb388b25fe..4ef84bc78c 100644 --- a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php @@ -2,6 +2,8 @@ namespace Drupal\Core\Extension; +use Drupal\Core\Requirements; + /** * Provides a list of installation profiles. */ @@ -15,7 +17,7 @@ class ProfileExtensionList extends ExtensionList { 'description' => '', 'package' => 'Other', 'version' => NULL, - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => Requirements::MINIMUM_PHP, ]; /** diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index d54ff1fa1a..ce3dafe86c 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Extension; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Requirements; use Drupal\Core\State\StateInterface; /** @@ -276,7 +277,7 @@ public function rebuildThemeData() { 'description' => '', 'features' => $this->defaultFeatures, 'screenshot' => 'screenshot.png', - 'php' => DRUPAL_MINIMUM_PHP, + 'php' => Requirements::MINIMUM_PHP, 'libraries' => [], ]; diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index 45355cc3f6..77b9eb2e90 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -6,6 +6,7 @@ */ use Drupal\Core\Database\Database; +use Drupal\Core\Requirements; use Drupal\Core\Url; use Drupal\Core\Utility\UpdateException; @@ -942,8 +943,8 @@ function hook_requirements($phase) { 'title' => t('PHP'), 'value' => ($phase == 'runtime') ? \Drupal::l(phpversion(), new Url('system.php')) : 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(), Requirements::MINIMUM_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => Requirements::MINIMUM_PHP]); $requirements['php']['severity'] = REQUIREMENT_ERROR; } diff --git a/core/lib/Drupal/Core/Requirements.php b/core/lib/Drupal/Core/Requirements.php new file mode 100644 index 0000000000..adbc599d66 --- /dev/null +++ b/core/lib/Drupal/Core/Requirements.php @@ -0,0 +1,24 @@ + DRUPAL_MINIMUM_PHP]); + if (version_compare($phpversion, Requirements::MINIMUM_PHP) < 0) { + $requirements['php']['description'] = t('Your PHP installation is too old. Drupal requires at least PHP %version.', ['%version' => Requirements::MINIMUM_PHP]); $requirements['php']['severity'] = REQUIREMENT_ERROR; // If PHP is old, it's not safe to continue with the requirements check. return $requirements; @@ -376,16 +377,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(Requirements::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' => Requirements::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' => Requirements::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' => Requirements::MINIMUM_PHP_MEMORY_LIMIT]); } if (!empty($description['phase'])) { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 964d7fe91a..7b34d22cf7 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -10,6 +10,7 @@ use Drupal\Core\Asset\AttachedAssetsInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Queue\QueueGarbageCollectionInterface; +use Drupal\Core\Requirements; use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Extension\Extension; use Drupal\Core\Form\FormStateInterface; diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 8c105f25ae..780b33c90e 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -368,6 +368,15 @@ protected function systemListReset() { if (!defined('DRUPAL_PHP_FUNCTION_PATTERN')) { define('DRUPAL_PHP_FUNCTION_PATTERN', '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'); } -if (!defined('DRUPAL_MINIMUM_PHP')) { - define('DRUPAL_MINIMUM_PHP', '5.3.10'); -} + +/** + * Minimum supported version of PHP. + * + * @deprecated in Drupal 8.6.0, will be removed before Drupal 9.0.0. Use + * \Drupal\Core\Requirements::MINIMUM_PHP instead. + * + * @see https://www.drupal.org/node/2909361 + */ + if (!defined('DRUPAL_MINIMUM_PHP')) { + define('DRUPAL_MINIMUM_PHP', '5.3.10'); + }