function VendorHardeningPlugin::cleanAllPackages

Same name in other branches
  1. 9 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanAllPackages()
  2. 10 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanAllPackages()
  3. 11.x 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.

Parameters

string $vendor_dir: Path to vendor directory

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 265

Class

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

Namespace

Drupal\Composer\Plugin\VendorHardening

Code

public function cleanAllPackages($vendor_dir) {
    // 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;
    }
    // Get all the packages that we should clean up but haven't already.
    $cleanup_packages = array_diff_key($this->config
        ->getAllCleanupPaths(), $this->packagesAlreadyCleaned);
    // Get all the packages that are installed that we should clean up.
    $packages_to_be_cleaned = array_intersect_key($cleanup_packages, $installed_packages);
    if (!$packages_to_be_cleaned) {
        $this->io
            ->writeError('<info>Vendor directory already clean.</info>');
        return;
    }
    $this->io
        ->writeError('<info>Cleaning vendor directory.</info>');
    foreach ($packages_to_be_cleaned as $package_name => $paths_for_package) {
        $this->cleanPathsForPackage($vendor_dir, $package_name, $paths_for_package);
    }
}

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