class AllowedPackages implements PostPackageEventListenerInterface (View source)

internal  
 

Determine recursively which packages have been allowed to scaffold files.

If the root-level composer.json allows drupal/core, and drupal/core allows drupal/assets, then the later package will also implicitly be allowed.

Properties

protected Composer $composer

The Composer service.

protected IOInterface $io

Composer's I/O service.

protected ManageOptions $manageOptions

Manager of the options in the top-level composer.json's 'extra' section.

protected array $newPackages

The list of new packages added by this Composer command.

Methods

__construct(Composer $composer, IOInterface $io, ManageOptions $manage_options)

AllowedPackages constructor.

PackageInterface[]
getAllowedPackages()

Gets a list of all packages that are allowed to copy scaffold files.

event(PackageEvent $event)

Handles package events during a 'composer require' operation.

array
getTopLevelAllowedPackages()

Gets all packages that are allowed in the top-level composer.json.

PackageInterface[]
recursiveGetAllowedPackages(array $packages_to_allow, array $allowed_packages = [])

Builds a name-to-package mapping from a list of package names.

PackageInterface[]
evaluateNewPackages(array $allowed_packages)

Evaluates newly-added packages and see if they are already allowed.

string
getOperationType(OperationInterface $operation)

Determine the type of the provided operation.

PackageInterface|null
getPackage(string $name)

Retrieves a package from the current composer process.

Details

__construct(Composer $composer, IOInterface $io, ManageOptions $manage_options)

AllowedPackages constructor.

Parameters

Composer $composer

The composer object.

IOInterface $io

IOInterface to write to.

ManageOptions $manage_options

Manager of the options in the top-level composer.json's 'extra' section.

PackageInterface[] getAllowedPackages()

Gets a list of all packages that are allowed to copy scaffold files.

We will implicitly allow the projects 'drupal/legacy-scaffold-assets' and 'drupal/core' to scaffold files, if they are present. Any other project must be explicitly whitelisted in the top-level composer.json file in order to be allowed to override scaffold files. Configuration for packages specified later will override configuration specified by packages listed earlier. In other words, the last listed package has the highest priority. The root package will always be returned at the end of the list.

Return Value

PackageInterface[]

An array of allowed Composer packages.

event(PackageEvent $event)

Handles package events during a 'composer require' operation.

Parameters

PackageEvent $event

Composer package event sent on install/update/remove.

protected array getTopLevelAllowedPackages()

Gets all packages that are allowed in the top-level composer.json.

We will implicitly allow the projects 'drupal/legacy-scaffold-assets' and 'drupal/core' to scaffold files, if they are present. Any other project must be explicitly whitelisted in the top-level composer.json file in order to be allowed to override scaffold files.

Return Value

array

An array of allowed Composer package names.

protected PackageInterface[] recursiveGetAllowedPackages(array $packages_to_allow, array $allowed_packages = [])

Builds a name-to-package mapping from a list of package names.

Parameters

array $packages_to_allow

List of package names to allow.

array $allowed_packages

Mapping of package names to PackageInterface of packages already accumulated.

Return Value

PackageInterface[]

Mapping of package names to PackageInterface in priority order.

protected PackageInterface[] evaluateNewPackages(array $allowed_packages)

Evaluates newly-added packages and see if they are already allowed.

For now we will only emit warnings if they are not.

Parameters

array $allowed_packages

Mapping of package names to PackageInterface of packages already accumulated.

Return Value

PackageInterface[]

Mapping of package names to PackageInterface in priority order.

protected string getOperationType(OperationInterface $operation)

Determine the type of the provided operation.

Adjusts API used for Composer 1 or Composer 2.

Parameters

OperationInterface $operation

The operation object.

Return Value

string

The operation type.

protected PackageInterface|null getPackage(string $name)

Retrieves a package from the current composer process.

Parameters

string $name

Name of the package to get from the current composer installation.

Return Value

PackageInterface|null

The Composer package.