function VendorHardeningPlugin::cleanPathsForPackage

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

Clean the installed directories for a named package.

Parameters

\Composer\Package\PackageInterface $package: The package to clean.

string[] $paths_for_package: List of directories in $package_name to remove

2 calls to VendorHardeningPlugin::cleanPathsForPackage()
VendorHardeningPlugin::cleanAllPackages in composer/Plugin/VendorHardening/VendorHardeningPlugin.php
Clean all configured packages.
VendorHardeningPlugin::cleanPackage in composer/Plugin/VendorHardening/VendorHardeningPlugin.php
Clean a single package.

File

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

Class

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

Namespace

Drupal\Composer\Plugin\VendorHardening

Code

protected function cleanPathsForPackage(PackageInterface $package, $paths_for_package) {
    // Whatever happens here, this package counts as cleaned so that we don't
    // process it more than once.
    $package_name = strtolower($package->getName());
    $this->packagesAlreadyCleaned[$package_name] = TRUE;
    $package_dir = $this->getInstallPathForPackage($package);
    if (!is_dir($package_dir)) {
        return;
    }
    $this->io
        ->writeError(sprintf('%sCleaning paths in <comment>%s</comment>', str_repeat(' ', 4), $package_name), TRUE, IOInterface::VERY_VERBOSE);
    $fs = new Filesystem();
    foreach ($paths_for_package as $cleanup_item) {
        $cleanup_path = $package_dir . '/' . $cleanup_item;
        if (!file_exists($cleanup_path)) {
            // If the package has changed or the --prefer-dist version does not
            // include the directory. This is not an error.
            $this->io
                ->writeError(sprintf("%s<comment>Path '%s' does not exist.</comment>", str_repeat(' ', 6), $cleanup_path), TRUE, IOInterface::VERY_VERBOSE);
            continue;
        }
        if (!$fs->remove($cleanup_path)) {
            // Always display a message if this fails as it means something
            // has gone wrong. Therefore the message has to include the
            // package name as the first informational message might not
            // exist.
            $this->io
                ->writeError(sprintf("%s<error>Failure removing path '%s'</error> in package <comment>%s</comment>.", str_repeat(' ', 6), $cleanup_item, $package_name), TRUE, IOInterface::NORMAL);
            continue;
        }
        $this->io
            ->writeError(sprintf("%sRemoving path <info>'%s'</info>", str_repeat(' ', 4), $cleanup_item), TRUE, IOInterface::VERBOSE);
    }
}

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