function FixtureManipulator::createPathRepo

Creates a path repo.

Parameters

array $package: A Composer package definition. Must include the `name` and `type` keys.

string $repo_path: The path at which to create a path repo for this package.

string|null $original_repo_path: If NULL: this is the first version of this package. Otherwise: a string containing the path repo to the first version of this package. This will be used to automatically inherit the same files (typically *.info.yml).

1 call to FixtureManipulator::createPathRepo()
FixtureManipulator::addRepository in core/modules/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php
Adds a path repository.

File

core/modules/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php, line 541

Class

FixtureManipulator
Manipulates a test fixture using Composer commands.

Namespace

Drupal\fixture_manipulator

Code

private function createPathRepo(array $package, string $repo_path, ?string $original_repo_path) : void {
    $fs = new SymfonyFileSystem();
    if (is_dir($repo_path)) {
        throw new \LogicException("A path repo already exists at {$repo_path}.");
    }
    // Create the repo if it does not exist.
    $fs->mkdir($repo_path);
    // Forks also get the original's additional files (e.g. *.info.yml files).
    if ($original_repo_path) {
        $fs->mirror($original_repo_path, $repo_path);
        // composer.json will be freshly generated by `composer init` below.
        $fs->remove($repo_path . '/composer.json');
    }
    // Switch the working directory from project root to repo path.
    $project_root_dir = $this->dir;
    $this->dir = $repo_path;
    // Create a composer.json file using `composer init`.
    $this->runComposerCommand([
        'init',
        static::getComposerInitOptionsForPackage($package),
    ]);
    // Set the `extra` property in the generated composer.json file using
    // `composer config`, because `composer init` does not support it.
    foreach ($package['extra'] ?? [] as $extra_property => $extra_value) {
        $this->runComposerCommand([
            'config',
            "extra.{$extra_property}",
            '--json',
            json_encode($extra_value, JSON_UNESCAPED_SLASHES),
        ]);
    }
    // Restore the project root as the working directory.
    $this->dir = $project_root_dir;
}

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