You are here

public function PackageManager::getRequiredPackages in Composer Manager 8

Returns the required packages.

This includes all extension requirements as well as any previously installed packages that are no longer required. The core requirements are not listed, for brevity.

Return value

array An array of packages, keyed by package name, with the following keys:

  • constraint: The imposed version constraint (e.g. '>=2.7').
  • description: Package description, if known.
  • homepage: Package homepage, if known.
  • require: Package requirements, if known.
  • required_by: An array of dependent package names. Empty if the package is no longer required.
  • version: The installed package version. Empty if the package hasn't been installed yet.

Overrides PackageManagerInterface::getRequiredPackages

1 call to PackageManager::getRequiredPackages()
PackageManager::needsComposerUpdate in src/PackageManager.php
Returns whether a composer update is needed.

File

src/PackageManager.php, line 107

Class

PackageManager
Manages composer packages.

Namespace

Drupal\composer_manager

Code

public function getRequiredPackages() {
  if (!isset($this->packages['required'])) {
    $merged_extension_package = $this
      ->buildMergedExtensionPackage();
    $packages = [];
    foreach ($merged_extension_package['require'] as $package_name => $constraint) {
      if (substr($package_name, 0, 7) != 'drupal/') {

        // Skip Drupal module requirements, add the rest.
        $packages[$package_name] = [
          'constraint' => $constraint,
        ];
      }
    }
    foreach ($this
      ->getInstalledPackages() as $package) {
      $package_name = $package['name'];
      if (!isset($packages[$package_name])) {
        continue;
      }

      // Add additional information available only for installed packages.
      $packages[$package_name] += [
        'description' => !empty($package['description']) ? $package['description'] : '',
        'homepage' => !empty($package['homepage']) ? $package['homepage'] : '',
        'require' => !empty($package['require']) ? $package['require'] : [],
        'version' => $package['version'],
      ];
      if ($package['version'] == 'dev-master') {
        $packages[$package_name]['version'] .= '#' . $package['source']['reference'];
      }
    }

    // Process and cache the package list.
    $this->packages['required'] = $this
      ->processRequiredPackages($packages);
  }
  return $this->packages['required'];
}