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

Breadcrumb

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

function 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

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);
}
RSS feed
Powered by Drupal