/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $filesystem = new Filesystem(); $packageName = $this->getPackageFilename($name = $this->argument('name')); if (!($targetDir = $this->option('dir'))) { $targetDir = $this->container->path(); } $sourcePath = $this->container->get('path.packages') . '/' . $name; $filesystem->ensureDirectoryExists($targetDir); $target = realpath($targetDir) . '/' . $packageName . '.zip'; $filesystem->ensureDirectoryExists(dirname($target)); $exludes = []; if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) { $jsonFile = new JsonFile($composerJsonPath); $jsonData = $jsonFile->read(); if (!empty($jsonData['archive']['exclude'])) { $exludes = $jsonData['archive']['exclude']; } if (!empty($jsonData['archive']['scripts'])) { system($jsonData['archive']['scripts'], $return); if ($return !== 0) { throw new \RuntimeException('Can not executes scripts.'); } } } $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.zip'; $filesystem->ensureDirectoryExists(dirname($tempTarget)); $archiver = new PharArchiver(); $archivePath = $archiver->archive($sourcePath, $tempTarget, 'zip', $exludes); rename($archivePath, $target); $filesystem->remove($tempTarget); return $target; }
public function testZipArchive() { // Set up repository $this->setupDummyRepo(); $package = $this->setupPackage(); $target = $this->getUniqueTmpDirectory() . '/composer_archiver_test.zip'; // Test archive $archiver = new PharArchiver(); $archiver->archive($package->getSourceUrl(), $target, 'zip'); $this->assertFileExists($target); $this->filesystem->removeDirectory(dirname($target)); }
public function testZipArchive() { // Set up repository $this->setupDummyRepo(); $package = $this->setupPackage(); $target = sys_get_temp_dir() . '/composer_archiver_test.zip'; // Test archive $archiver = new PharArchiver(); $archiver->archive($package->getSourceUrl(), $target, 'zip'); $this->assertFileExists($target); unlink($target); }