function FixtureManipulator::addRepository
Adds a path repository.
Parameters
array $package: A Composer package definition. Must include the `name` and `type` keys.
Return value
string The repository path.
2 calls to FixtureManipulator::addRepository()
- FixtureManipulator::addPackage in core/
modules/ package_manager/ tests/ modules/ fixture_manipulator/ src/ FixtureManipulator.php - Adds a package.
- FixtureManipulator::modifyPackageConfig in core/
modules/ package_manager/ tests/ modules/ fixture_manipulator/ src/ FixtureManipulator.php - Modifies a package's composer.json properties.
File
-
core/
modules/ package_manager/ tests/ modules/ fixture_manipulator/ src/ FixtureManipulator.php, line 602
Class
- FixtureManipulator
- Manipulates a test fixture using Composer commands.
Namespace
Drupal\fixture_manipulatorCode
private function addRepository(array $package) : string {
$name = $package['name'];
$path_repo_base = \Drupal::state()->get(self::PATH_REPO_STATE_KEY);
$repo_path = "{$path_repo_base}/" . str_replace('/', '--', $name);
// Determine if the given $package is a new package or a fork of an existing
// one (that means it's either the same version but with other metadata, or
// a new version with other metadata). Existing path repos are never
// modified, not even if the same version of a package is assigned other
// metadata. This allows always comparing with the original metadata.
$is_new_or_fork = !is_dir($repo_path) ? 'new' : 'fork';
if ($is_new_or_fork === 'fork') {
$original_composer_json_path = $repo_path . DIRECTORY_SEPARATOR . 'composer.json';
$original_repo_path = $repo_path;
$original_composer_json_data = json_decode(file_get_contents($original_composer_json_path), TRUE, flags: JSON_THROW_ON_ERROR);
$forked_composer_json_data = NestedArray::mergeDeep($original_composer_json_data, $package);
if ($original_composer_json_data === $forked_composer_json_data) {
throw new \LogicException(sprintf('Nothing is actually different in this fork of the package %s.', $package['name']));
}
$package = $forked_composer_json_data;
$repo_path .= "--{$package['version']}";
// Cannot create multiple forks with the same version. This is likely
// due to a test simulating a failed Stage::apply().
if (!is_dir($repo_path)) {
$this->createPathRepo($package, $repo_path, $original_repo_path);
}
}
else {
$this->createPathRepo($package, $repo_path, NULL);
}
// Add the package to the Composer repository defined for the site.
$packages_json = $this->dir . '/packages.json';
$packages_data = file_get_contents($packages_json);
$packages_data = json_decode($packages_data, TRUE, flags: JSON_THROW_ON_ERROR);
$version = $package['version'];
$package['dist'] = [
'type' => 'path',
'url' => $repo_path,
];
$packages_data['packages'][$name][$version] = $package;
assert(file_put_contents($packages_json, json_encode($packages_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) !== FALSE);
return $repo_path;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.