function VendorHardeningPlugin::cleanAllPackages

Same name in other branches
  1. 9 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanAllPackages()
  2. 8.9.x composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanAllPackages()
  3. 10 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanAllPackages()

Clean all configured packages.

This applies in the context of a post-command event.

1 call to VendorHardeningPlugin::cleanAllPackages()
VendorHardeningPlugin::onPostCmd in composer/Plugin/VendorHardening/VendorHardeningPlugin.php
POST_UPDATE_CMD and POST_INSTALL_CMD event handler.

File

composer/Plugin/VendorHardening/VendorHardeningPlugin.php, line 278

Class

VendorHardeningPlugin
A Composer plugin to clean out your project's vendor directory.

Namespace

Drupal\Composer\Plugin\VendorHardening

Code

public function cleanAllPackages() : void {
    // Get a list of all the packages available after the update or install
    // command.
    $installed_packages = [];
    foreach ($this->getInstalledPackages() as $package) {
        // Normalize package names to lower case.
        $installed_packages[strtolower($package->getName())] = $package;
    }
    $all_cleanup_paths = $this->config
        ->getAllCleanupPaths();
    // Get all the packages that we should clean up but haven't already.
    $cleanup_paths = array_diff_key($all_cleanup_paths, $this->packagesAlreadyCleaned);
    // Get all the packages that are installed that we should clean up.
    $packages_to_be_cleaned = array_intersect_key($cleanup_paths, $installed_packages);
    if (!$packages_to_be_cleaned) {
        $this->io
            ->writeError('<info>Packages already clean.</info>');
        return;
    }
    $this->io
        ->writeError('<info>Cleaning installed packages.</info>');
    foreach ($packages_to_be_cleaned as $package_name => $paths) {
        $this->cleanPathsForPackage($installed_packages[$package_name], $all_cleanup_paths[$package_name]);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.