function LegacyVersionUtility::convertToLegacyVersion
Converts a version number to a legacy version if needed and possible.
Parameters
string $version_string: The version number.
Return value
string|null The version number, converted if needed, or NULL if not possible. Only semantic version numbers that have patch level of 0 can be converted into legacy version numbers.
1 call to LegacyVersionUtility::convertToLegacyVersion()
- SupportedReleaseValidator::isSupportedRelease in core/
modules/ package_manager/ src/ Validator/ SupportedReleaseValidator.php - Checks if the given version of a project is supported.
File
-
core/
modules/ package_manager/ src/ LegacyVersionUtility.php, line 50
Class
- LegacyVersionUtility
- A utility class for dealing with legacy version numbers.
Namespace
Drupal\package_managerCode
public static function convertToLegacyVersion($version_string) : ?string {
if (self::isLegacyVersion($version_string)) {
return $version_string;
}
$version = ExtensionVersion::createFromVersionString($version_string);
if ($extra = $version->getVersionExtra()) {
$version_string_without_extra = str_replace("-{$extra}", '', $version_string);
}
else {
$version_string_without_extra = $version_string;
}
[
,
,
$patch,
] = explode('.', $version_string_without_extra);
// A semantic version can only be converted to legacy if it's patch level is
// '0'.
if ($patch !== '0') {
return NULL;
}
return '8.x-' . $version->getMajorVersion() . '.' . $version->getMinorVersion() . ($extra ? "-{$extra}" : '');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.