Пример #1
0
 /**
  * Get the full path to the config fixture directory for a given package.
  *
  * @param  Composer    $composer The current Composer instance
  * @param  BasePackage $package  The package to get the directory for
  *
  * @return string                Full path to the package's config fixture dir
  */
 public static function getConfigFixtureDir(Composer $composer, BasePackage $package)
 {
     return implode('/', array(realpath($composer->getConfig()->get('vendor-dir')), $package->getPrettyName(), $package->getTargetDir(), static::CONFIG_FIXTURE_PATH));
 }
Пример #2
0
 /**
  * Clean a package, based on its rules.
  *
  * @param BasePackage $package The package to clean
  * @return bool True if cleaned
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function cleanPackage(BasePackage $package)
 {
     $vendorDir = $this->config->get('vendor-dir');
     $targetDir = $package->getTargetDir();
     $packageName = $package->getPrettyName();
     $packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName;
     $rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null;
     if (!$rules) {
         $this->io->writeError('Rules not found: ' . $packageName);
         return false;
     }
     $dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir));
     if (!is_dir($dir)) {
         $this->io->writeError('Vendor dir not found: ' . $vendorDir . '/' . $packageDir);
         return false;
     }
     //$this->io->write('Rules: ' . print_r($rules, true));
     foreach ((array) $rules as $part) {
         // Split patterns for single globs (should be max 260 chars)
         $patterns = (array) $part;
         foreach ($patterns as $pattern) {
             try {
                 foreach (glob($dir . '/' . $pattern) as $file) {
                     $this->filesystem->remove($file);
                     //$this->io->write('File removed: ' . $file);
                 }
             } catch (\Exception $e) {
                 $this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage());
             }
         }
     }
     return true;
 }
 /**
  * Clean a package, based on its rules.
  *
  * @param BasePackage  $package  The package to clean
  * @return bool True if cleaned
  */
 protected function cleanPackage(BasePackage $package)
 {
     // Only clean 'dist' packages
     if ($package->getInstallationSource() !== 'dist') {
         return false;
     }
     $vendorDir = $this->config->get('vendor-dir');
     $targetDir = $package->getTargetDir();
     $packageName = $package->getPrettyName();
     $packageDir = $targetDir ? $packageName . '/' . $targetDir : $packageName;
     $rules = isset($this->rules[$packageName]) ? $this->rules[$packageName] : null;
     if (!$rules) {
         return;
     }
     $dir = $this->filesystem->normalizePath(realpath($vendorDir . '/' . $packageDir));
     if (!is_dir($dir)) {
         return false;
     }
     foreach ((array) $rules as $part) {
         // Split patterns for single globs (should be max 260 chars)
         $patterns = explode(' ', trim($part));
         foreach ($patterns as $pattern) {
             try {
                 foreach (glob($dir . '/' . $pattern) as $file) {
                     $this->filesystem->remove($file);
                 }
             } catch (\Exception $e) {
                 $this->io->write("Could not parse {$packageDir} ({$pattern}): " . $e->getMessage());
             }
         }
     }
     return true;
 }