diff --git a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php index 8e1ba2a187..d54304cfc9 100644 --- a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php +++ b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php @@ -64,7 +64,7 @@ public function parse($filename) { throw new InfoParserException("Invalid 'core' value \"{$parsed_info['core']}\" in " . $filename); } if (isset($parsed_info['core_version_requirement'])) { - $supports_pre_core_version_requirement_version = static::isConstraintSatisfiedByPreCoreVersionRequirementCoreVersion($parsed_info['core_version_requirement']); + $supports_pre_core_version_requirement_version = static::isConstraintSatisfiedByPreviousVersion($parsed_info['core_version_requirement'], static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION); // If the 'core_version_requirement' constraint does not satisfy any // Drupal 8 versions before 8.7.7 then 'core' cannot be set or it will // effectively support all versions of Drupal 8 because @@ -127,65 +127,76 @@ protected function getRequiredKeys() { } /** - * Determines if a constraint is satisfied by earlier versions of Drupal. + * Determines if a constraint is satisfied by earlier versions of Drupal 8. * * @param string $constraint * A core semantic version constraint. + * @param string $version + * A core version. * * @return bool - * TRUE if the constraint is satisfied by a core version that does not - * support the 'core_version_requirement' key in info.yml files. + * TRUE if the constraint is satisfied by a core version prior to the + * provided version. */ - protected static function isConstraintSatisfiedByPreCoreVersionRequirementCoreVersion($constraint) { + protected static function isConstraintSatisfiedByPreviousVersion($constraint, $version) { static $evaluated_constraints = []; - if (!isset($evaluated_constraints[$constraint])) { - $evaluated_constraints[$constraint] = FALSE; - foreach (static::getAllPreCoreVersionRequirementCoreVersions() as $version) { - if (static::satisfies($version, $constraint)) { - $evaluated_constraints[$constraint] = TRUE; - // The constraint only has to satisfy one version so break when the - // first one is found. + // Any particular constraint and version combination only needs to be + // evaluated once. + if (!isset($evaluated_constraints[$constraint][$version])) { + $evaluated_constraints[$constraint][$version] = FALSE; + foreach (static::getAllPreviousCoreVersions($version) as $previous_version) { + if (static::satisfies($previous_version, $constraint)) { + $evaluated_constraints[$constraint][$version] = TRUE; + // The constraint only has to satisfy one previous version so break + // when the first one is found. break; } } } - return $evaluated_constraints[$constraint]; + return $evaluated_constraints[$constraint][$version]; } /** - * Gets all the version of Drupal 8 before 8.7.7. + * Gets all the versions of Drupal 8 before a specific version. + * + * @param string $version + * The version to get versions before. * * @return array * All of the applicable Drupal 8 releases. */ - protected static function getAllPreCoreVersionRequirementCoreVersions() { - static $versions = []; - if (empty($versions)) { + protected static function getAllPreviousCoreVersions($version) { + static $versions_lists = []; + // Check if list of previous versions for the specified version has already + // been created. + if (empty($versions_lists[$version])) { // Loop through all minor versions including 8.7. foreach (range(0, 7) as $minor) { // The largest patch number in a release was 17 in 8.6.17. Use 27 to // leave room for future security releases. foreach (range(0, 27) as $patch) { $patch_version = "8.$minor.$patch"; - if ($patch_version === static::FIRST_CORE_VERSION_REQUIREMENT_SUPPORTED_VERSION) { + if ($patch_version === $version) { // Reverse the order of the versions so that they will be evaluated // from the most recent versions first. - $versions = array_reverse($versions); - return $versions; + $versions_lists[$version] = array_reverse($versions_lists[$version]); + return $versions_lists[$version]; } - $versions[] = $patch_version; if ($patch === 0) { + // If this is a '0' patch release like '8.1.0' first create the + // pre-release versions such as '8.1.0-alpha1' and '8.1.0-rc1'. foreach (['alpha', 'beta', 'rc'] as $prerelease) { // The largest prerelease number was in 8.0.0-beta16. foreach (range(0, 16) as $prerelease_number) { - $versions[] = "$patch_version-$prerelease$prerelease_number"; + $versions_lists[$version][] = "$patch_version-$prerelease$prerelease_number"; } } } + $versions_lists[$version][] = $patch_version; } } } - return $versions; + return $versions_lists[$version]; } }