function Composer::setDrupalVersion

Same name in other branches
  1. 10 composer/Composer.php \Drupal\Composer\Composer::setDrupalVersion()
  2. 11.x composer/Composer.php \Drupal\Composer\Composer::setDrupalVersion()

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.

Throws

\UnexpectedValueException

2 calls to Composer::setDrupalVersion()
ComponentsTaggedReleaseTest::testReleaseTagging in core/tests/Drupal/BuildTests/Composer/Component/ComponentsTaggedReleaseTest.php
Validate release tagging and regeneration of dependencies.
ComposerProjectTemplatesTest::testTemplateCreateProject in core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php
@dataProvider provideTemplateCreateProject

File

composer/Composer.php, line 56

Class

Composer
Provides static functions for composer script events.

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.