3 || $version_parts_count < 2 || !is_numeric($major_version) || ($version_parts_count === 3 && !is_numeric($version_parts[1])) // The only case where a non-numeric version part other the extra part is // allowed is in development versions like 8.x-1.x-dev, 1.2.x-dev or // 1.x-dev. || (!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); } /** * Constructs an ExtensionVersion object. * * @param string $major_version * The major version. * @param string|null $minor_version * The minor version. * @param string|null $version_extra * The extra version string. */ private function __construct(string $major_version, ?string $minor_version, ?string $version_extra) { $this->majorVersion = $major_version; $this->minorVersion = $minor_version; $this->versionExtra = $version_extra; } /** * Constructs an ExtensionVersion version object from a support branch. * * This can be used to determine the major version of the branch. * ::getVersionExtra() will always return NULL for branches. * * @param string $branch * The support branch. * * @return \Drupal\Core\Extension\ExtensionVersion * The ExtensionVersion instance. */ public static function createFromSupportBranch(string $branch): ExtensionVersion { if (!str_ends_with($branch, '.')) { throw new \UnexpectedValueException("Invalid support branch: $branch"); } return static::createFromVersionString($branch . '0'); } /** * Gets the major version. * * @return string * The major version. */ public function getMajorVersion(): string { return $this->majorVersion; } /** * Gets the minor version. * * @return string|null * The minor version. */ public function getMinorVersion(): ?string { return $this->minorVersion; } /** * Gets the version extra string at the end of the version number. * * @return string|null * The version extra string if available, or otherwise NULL. */ public function getVersionExtra(): ?string { return $this->versionExtra; } }