trait EventWithPackageListTrait
Common methods for pre- and post-require events.
@internal This is an internal part of Automatic Updates and should only be used by \Drupal\package_manager\Event\PreRequireEvent and \Drupal\package_manager\Event\PostRequireEvent.
Hierarchy
- trait \Drupal\package_manager\Event\EventWithPackageListTrait
File
-
core/
modules/ package_manager/ src/ Event/ EventWithPackageListTrait.php, line 17
Namespace
Drupal\package_manager\EventView source
trait EventWithPackageListTrait {
/**
* The runtime packages, in the form 'vendor/name:constraint'.
*
* @var string[]
*/
private $runtimePackages;
/**
* The dev packages to be required, in the form 'vendor/name:constraint'.
*
* @var string[]
*/
private $devPackages;
/**
* Constructs the object.
*
* @param \Drupal\package_manager\SandboxManagerBase $sandboxManager
* The stage.
* @param string[] $runtime_packages
* The runtime (i.e., non-dev) packages to be required, in the form
* 'vendor/name:constraint'.
* @param string[] $dev_packages
* The dev packages to be required, in the form 'vendor/name:constraint'.
*/
public function __construct(SandboxManagerBase $sandboxManager, array $runtime_packages, array $dev_packages = []) {
$this->runtimePackages = $runtime_packages;
$this->devPackages = $dev_packages;
parent::__construct($sandboxManager);
}
/**
* Gets the runtime (i.e., non-dev) packages.
*
* @return string[]
* An array of packages where the keys are package names in the form
* `vendor/name` and the values are version constraints. Packages without a
* version constraint will default to `*`.
*/
public function getRuntimePackages() : array {
return $this->getKeyedPackages($this->runtimePackages);
}
/**
* Gets the dev packages.
*
* @return string[]
* An array of packages where the values are version constraints and keys
* are package names in the form `vendor/name`. Packages without a version
* constraint will default to `*`.
*/
public function getDevPackages() : array {
return $this->getKeyedPackages($this->devPackages);
}
/**
* Gets packages as a keyed array.
*
* @param string[] $packages
* The packages, in the form 'vendor/name:version'.
*
* @return string[]
* An array of packages where the values are version constraints and keys
* are package names in the form `vendor/name`. Packages without a version
* constraint will default to `*`.
*/
private function getKeyedPackages(array $packages) : array {
$keyed_packages = [];
foreach ($packages as $package) {
if (strpos($package, ':') > 0) {
[
$name,
$constraint,
] = explode(':', $package);
}
else {
[
$name,
$constraint,
] = [
$package,
'*',
];
}
$keyed_packages[$name] = $constraint;
}
return $keyed_packages;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
EventWithPackageListTrait::$devPackages | private | property | The dev packages to be required, in the form 'vendor/name:constraint'. |
EventWithPackageListTrait::$runtimePackages | private | property | The runtime packages, in the form 'vendor/name:constraint'. |
EventWithPackageListTrait::getDevPackages | public | function | Gets the dev packages. |
EventWithPackageListTrait::getKeyedPackages | private | function | Gets packages as a keyed array. |
EventWithPackageListTrait::getRuntimePackages | public | function | Gets the runtime (i.e., non-dev) packages. |
EventWithPackageListTrait::__construct | public | function | Constructs the object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.