function PackageGenerator::generateMetapackage

Same name in other branches
  1. 9 composer/Generator/PackageGenerator.php \Drupal\Composer\Generator\PackageGenerator::generateMetapackage()
  2. 8.9.x composer/Generator/PackageGenerator.php \Drupal\Composer\Generator\PackageGenerator::generateMetapackage()
  3. 10 composer/Generator/PackageGenerator.php \Drupal\Composer\Generator\PackageGenerator::generateMetapackage()

Generate one metapackage.

Parameters

\Composer\IO\IOInterface $io: Composer IO object for interacting with the user.

BuilderInterface $builder: An object that can build a metapackage.

Return value

bool TRUE if the generated metapackage is different than what is on disk.

1 call to PackageGenerator::generateMetapackage()
PackageGenerator::generate in composer/Generator/PackageGenerator.php
Generate Drupal's metapackages whenever composer.lock is updated.

File

composer/Generator/PackageGenerator.php, line 87

Class

PackageGenerator
Generates metapackages.

Namespace

Drupal\Composer\Generator

Code

protected function generateMetapackage(IOInterface $io, BuilderInterface $builder) {
    // Load the existing composer.json file for drupal/core-recommended
    $relative_path = $builder->getPath() . '/composer.json';
    $composer_json_path = $this->generatedProjectBaseDir . '/' . $relative_path;
    $original_composer_json = file_exists($composer_json_path) ? file_get_contents($composer_json_path) : '';
    // Get the composer.json file from the builder.
    $composer_json_data = $builder->getPackage();
    $updated_composer_json = static::encode($composer_json_data);
    // Exit early if nothing changed.
    if (trim($original_composer_json, " \t\r\x00\v") == trim($updated_composer_json, " \t\r\x00\v")) {
        return FALSE;
    }
    // Warn the user that a metapackage file has been updated..
    $io->write("Updated metapackage file <info>composer/Metapackage/{$relative_path}</info>.");
    // Write the composer.json file back to disk
    $fs = new Filesystem();
    $fs->ensureDirectoryExists(dirname($composer_json_path));
    file_put_contents($composer_json_path, $updated_composer_json);
    return TRUE;
}

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