Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExtensionVersion.php

function ExtensionVersion::createFromVersionString

Constructs an extension version object from a version string.

Parameters

string $version_string: The version string.

Return value

\Drupal\Core\Extension\ExtensionVersion The extension version instance.

9 calls to ExtensionVersion::createFromVersionString()
ExtensionVersion::createFromSupportBranch in core/lib/Drupal/Core/Extension/ExtensionVersion.php
Constructs an ExtensionVersion version object from a support branch.
LegacyVersionUtility::convertToLegacyVersion in core/modules/package_manager/src/LegacyVersionUtility.php
Converts a version number to a legacy version if needed and possible.
ProjectInfo::isInstallable in core/modules/package_manager/src/ProjectInfo.php
Determines if a release can be installed.
ProjectSecurityData::getAdditionalSecurityCoveredMinors in core/modules/update/src/ProjectSecurityData.php
Gets the number of additional minor releases with security coverage.
ProjectSecurityData::getCoverageInfo in core/modules/update/src/ProjectSecurityData.php
Gets the security coverage information for a project.

... See full list

File

core/lib/Drupal/Core/Extension/ExtensionVersion.php, line 54

Class

ExtensionVersion
Provides an extension version value object.

Namespace

Drupal\Core\Extension

Code

public static function createFromVersionString(string $version_string) : ExtensionVersion {
    $original_version = $version_string;
    if (str_starts_with($version_string, static::CORE_PREFIX) && $version_string !== '8.x-dev') {
        $version_string = preg_replace('/8\\.x-/', '', $version_string, 1);
    }
    else {
        // Ensure the version string has no unsupported core prefixes.
        $dot_x_position = strpos($version_string, '.x-');
        if ($dot_x_position === 1 || $dot_x_position === 2) {
            $after_core_prefix = explode('.x-', $version_string)[1];
            if ($after_core_prefix !== 'dev') {
                throw new \UnexpectedValueException("Unexpected version core prefix in {$version_string}. The only core prefix expected in \\Drupal\\Core\\Extension\\ExtensionVersion is: 8.x-");
            }
        }
    }
    $version_parts = explode('.', $version_string);
    $major_version = $version_parts[0];
    $version_parts_count = count($version_parts);
    if ($version_parts_count === 2) {
        $minor_version = NULL;
    }
    elseif ($version_parts_count === 3) {
        $minor_version = $version_parts[1];
    }
    $last_part_split = explode('-', $version_parts[count($version_parts) - 1]);
    $version_extra = count($last_part_split) === 1 ? NULL : $last_part_split[1];
    if ($version_parts_count > 3 || $version_parts_count < 2 || !is_numeric($major_version) || $version_parts_count === 3 && !is_numeric($version_parts[1]) || !is_numeric($last_part_split[0]) && $last_part_split !== 'x' && $version_extra !== 'dev') {
        throw new \UnexpectedValueException("Unexpected version number in: {$original_version}");
    }
    return new static($major_version, $minor_version, $version_extra);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal