function VendorHardeningPlugin::cleanPathsForPackage
Same name in other branches
- 9 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanPathsForPackage()
- 10 composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanPathsForPackage()
- 11.x composer/Plugin/VendorHardening/VendorHardeningPlugin.php \Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin::cleanPathsForPackage()
Clean the installed directories for a named package.
Parameters
string $vendor_dir: Path to vendor directory.
string $package_name: Name of package to sanitize.
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 326
Class
- VendorHardeningPlugin
- A Composer plugin to clean out your project's vendor directory.
Namespace
Drupal\Composer\Plugin\VendorHardeningCode
protected function cleanPathsForPackage($vendor_dir, $package_name, $paths_for_package) {
// Whatever happens here, this package counts as cleaned so that we don't
// process it more than once.
$this->packagesAlreadyCleaned[$package_name] = TRUE;
$package_dir = $vendor_dir . '/' . $package_name;
if (!is_dir($package_dir)) {
return;
}
$this->io
->writeError(sprintf('%sCleaning directories 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 (!is_dir($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>Directory '%s' does not exist.</comment>", str_repeat(' ', 6), $cleanup_path), TRUE, IOInterface::VERY_VERBOSE);
continue;
}
if (!$fs->removeDirectory($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 directory '%s'</error> in package <comment>%s</comment>.", str_repeat(' ', 6), $cleanup_item, $package_name), TRUE, IOInterface::NORMAL);
continue;
}
$this->io
->writeError(sprintf("%sRemoving directory <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.