Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CanonicalPackagesTrait.php

trait CanonicalPackagesTrait

Provides getCanonicalPackages() to various repository implementations

@internal

Hierarchy

  • trait \Composer\Repository\CanonicalPackagesTrait

File

vendor/composer/composer/src/Composer/Repository/CanonicalPackagesTrait.php, line 23

Namespace

Composer\Repository
View source
trait CanonicalPackagesTrait {
    
    /**
     * Get unique packages (at most one package of each name), with aliases resolved and removed.
     *
     * @return PackageInterface[]
     */
    public function getCanonicalPackages() {
        $packages = $this->getPackages();
        // get at most one package of each name, preferring non-aliased ones
        $packagesByName = [];
        foreach ($packages as $package) {
            if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
                $packagesByName[$package->getName()] = $package;
            }
        }
        $canonicalPackages = [];
        // unfold aliased packages
        foreach ($packagesByName as $package) {
            while ($package instanceof AliasPackage) {
                $package = $package->getAliasOf();
            }
            $canonicalPackages[] = $package;
        }
        return $canonicalPackages;
    }

}

Members

Title Sort descending Modifiers Object type Summary
CanonicalPackagesTrait::getCanonicalPackages public function Get unique packages (at most one package of each name), with aliases resolved and removed.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal