setArchiveBaseDir() public method

public setArchiveBaseDir ( $newArchiveBaseDir ) : ZipArchive
return ZipArchive
Example #1
0
 /**
  * @param string $cacheDir
  * @param string $targetDir
  * @param \Composer\Package\PackageInterface $package
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @param \Composer\Util\ProcessExecutor $process
  * @return string
  * @throws \Exception
  */
 protected function createZipFile($cacheDir, $targetDir, \Composer\Package\PackageInterface $package, OutputInterface $output, \Composer\Util\ProcessExecutor $process)
 {
     $zipfileName = str_replace('/', '_', strtolower($package->getPrettyName()));
     if ($package->getDistType() === 'pear') {
         $rootPath = $cacheDir;
         $zipPath = escapeshellarg($package->getPrettyName());
     } else {
         if ($package->getTargetDir()) {
             $rootPath = $cacheDir . '/' . $package->getPrettyName() . '/' . $package->getTargetDir();
             $zipPath = '.';
         } else {
             $rootPath = $cacheDir . '/' . $package->getPrettyName();
             $zipPath = '.';
         }
     }
     $output->writeln('  - ' . $zipfileName . '.zip');
     if (!class_exists('ZipArchive')) {
         $command = 'cd ' . escapeshellarg($rootPath) . ' && zip -9 -r ' . escapeshellarg($targetDir . '/dists/' . $zipfileName . '.zip') . ' ' . $zipPath;
         $result = $process->execute($command);
         if ($result) {
             throw new \Exception('could not create dist package for ' . $package->getName());
         }
     } else {
         $zipFile = $targetDir . '/dists/' . $zipfileName . '.zip';
         $zipArchive = new ZipArchive();
         $zipArchive->addExcludeDirectory('.svn');
         $zipArchive->setArchiveBaseDir($rootPath);
         if (($result = $zipArchive->open($zipFile, ZipArchive::OVERWRITE)) === TRUE) {
             $zipArchive->addDir($rootPath);
             $zipArchive->close();
         } else {
             throw new \Exception('could not create dist package for ' . $package->getName() . ' error code: ' . $result);
         }
     }
     return $zipfileName;
 }