class UnpackManager
Manages the recipe unpacking process.
@internal
Hierarchy
- class \Drupal\Composer\Plugin\RecipeUnpack\UnpackManager
Expanded class hierarchy of UnpackManager
File
-
composer/
Plugin/ RecipeUnpack/ UnpackManager.php, line 16
Namespace
Drupal\Composer\Plugin\RecipeUnpackView source
final readonly class UnpackManager {
/**
* The root composer with the root dependencies to be manipulated.
*/
private RootComposer $rootComposer;
/**
* The unpack options.
*/
public UnpackOptions $unpackOptions;
public function __construct(Composer $composer, IOInterface $io) {
$this->rootComposer = new RootComposer($composer, $io);
$this->unpackOptions = UnpackOptions::create($composer->getPackage()
->getExtra());
}
/**
* Unpacks the packages in the provided collection.
*
* @param \Drupal\Composer\Plugin\RecipeUnpack\UnpackCollection $unpackCollection
* The collection of recipe packages to unpack.
*/
public function unpack(UnpackCollection $unpackCollection) : void {
if (count($unpackCollection) === 0) {
// Early return to avoid unnecessary work.
return;
}
foreach ($unpackCollection as $package) {
$unpacker = new Unpacker($package, $this->composer, $this->rootComposer, $unpackCollection, $this->unpackOptions, $this->io);
$unpacker->unpackDependencies();
$this->io
->write("<info>{$package->getName()}</info> unpacked.");
}
// Unpacking uses \Composer\Semver\Intervals::isSubsetOf() to choose between
// constraints.
Intervals::clear();
$this->rootComposer
->writeFiles();
}
/**
* Determines if the provided package is present in the root composer.json.
*
* @param string $package_name
* The package name to check.
*
* @return bool
* TRUE if the package is present in the root composer.json, FALSE if not.
*/
public function isRootDependency(string $package_name) : bool {
$root_package = $this->composer
->getPackage();
return isset($root_package->getRequires()[$package_name]) || isset($root_package->getDevRequires()[$package_name]);
}
/**
* Checks if a package is a dev requirement.
*
* @param \Composer\Package\PackageInterface $package
* The package to check.
*
* @return bool
* TRUE if the package is present in require-dev or due to a package in
* require-dev, FALSE if not.
*/
public static function isDevRequirement(PackageInterface $package) : bool {
// Check if package is either a regular or dev requirement.
return InstalledVersions::isInstalled($package->getName()) && !InstalledVersions::isInstalled($package->getName(), FALSE);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
UnpackManager::$rootComposer | private | property | The root composer with the root dependencies to be manipulated. |
UnpackManager::$unpackOptions | public | property | The unpack options. |
UnpackManager::isDevRequirement | public static | function | Checks if a package is a dev requirement. |
UnpackManager::isRootDependency | public | function | Determines if the provided package is present in the root composer.json. |
UnpackManager::unpack | public | function | Unpacks the packages in the provided collection. |
UnpackManager::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.