You are here

public static function Composer::setDrupalVersion in Drupal 9

Set the version of Drupal; used in release process and by the test suite.

Parameters

string $root: Path to root of drupal/drupal repository.

string $version: Semver version to set Drupal's version to.

Return value

string Stability level of the provided version (stable, RC, alpha, etc.)

Throws

\UnexpectedValueException

1 call to Composer::setDrupalVersion()
ComposerProjectTemplatesTest::testTemplateCreateProject in core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@dataProvider provideTemplateCreateProject

File

composer/Composer.php, line 46

Class

Composer
Provides static functions for composer script events. See also core/lib/Drupal/Composer/Composer.php, which contains similar scripts needed by projects that include drupal/core. Scripts that are only needed by drupal/drupal go here.

Namespace

Drupal\Composer

Code

public static function setDrupalVersion(string $root, string $version) : void {

  // We use VersionParser::normalize to validate that $version is valid.
  // It will throw an exception if it is not.
  $versionParser = new VersionParser();
  $versionParser
    ->normalize($version);

  // Rewrite Drupal.php with the provided version string.
  $drupal_static_path = "{$root}/core/lib/Drupal.php";
  $drupal_static_source = file_get_contents($drupal_static_path);
  $drupal_static_source = preg_replace('#const VERSION = [^;]*#', "const VERSION = '{$version}'", $drupal_static_source);
  file_put_contents($drupal_static_path, $drupal_static_source);

  // Update the template project stability to match the version we set.
  static::setTemplateProjectStability($root, $version);
}