function FixtureManipulator::getComposerInitOptionsForPackage

Transform the received $package into options for `composer init`.

Parameters

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

Return value

array The corresponding `composer init` options.

1 call to FixtureManipulator::getComposerInitOptionsForPackage()
FixtureManipulator::createPathRepo in core/modules/package_manager/tests/modules/fixture_manipulator/src/FixtureManipulator.php
Creates a path repo.

File

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

Class

FixtureManipulator
Manipulates a test fixture using Composer commands.

Namespace

Drupal\fixture_manipulator

Code

private static function getComposerInitOptionsForPackage(array $package) : array {
  return array_filter(array_map(function ($k, $v) {
    switch ($k) {
      case 'name':
      case 'description':
      case 'type':
        return "--{$k}={$v}";
      case 'require':
      case 'require-dev':
        if (empty($v)) {
          return NULL;
        }
        $requirements = array_map(fn(string $req_package, string $req_version): string => "{$req_package}:{$req_version}", array_keys($v), array_values($v));
        return "--{$k}=" . implode(',', $requirements);
      case 'version':
        // This gets set in the repository metadata itself.
        return NULL;
      case 'extra':
        // Cannot be set using `composer init`, only `composer config` can.
        return NULL;
      default:
        throw new \InvalidArgumentException($k);
    }
  }, array_keys($package), array_values($package)));
}

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