function ComposerInspector::getPackageTypes

Loads package types from the lock file.

The package type is not available using `composer show` for listing packages. To avoiding making many calls to `composer show package-name`, load the lock file data to get the `type` key.

Parameters

array $packages_data: The packages data returned from ::show().

string $working_dir: The directory where Composer was run.

Return value

array The packages data, with a `type` key added to each package.

1 call to ComposerInspector::getPackageTypes()
ComposerInspector::getInstalledPackagesList in core/modules/package_manager/src/ComposerInspector.php
Returns the installed packages list.

File

core/modules/package_manager/src/ComposerInspector.php, line 353

Class

ComposerInspector
Defines a class to get information from Composer.

Namespace

Drupal\package_manager

Code

private function getPackageTypes(array $packages_data, string $working_dir) : array {
  $lock_content = file_get_contents($working_dir . DIRECTORY_SEPARATOR . 'composer.lock');
  $lock_data = json_decode($lock_content, TRUE, flags: JSON_THROW_ON_ERROR);
  $lock_packages = array_merge($lock_data['packages'] ?? [], $lock_data['packages-dev'] ?? []);
  foreach ($lock_packages as $lock_package) {
    $name = $lock_package['name'];
    if (isset($packages_data[$name]) && isset($lock_package['type'])) {
      $packages_data[$name]['type'] = $lock_package['type'];
    }
  }
  return $packages_data;
}

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