*/ class ArchiveCommand extends BaseCommand { use CompletionTrait; private const FORMATS = ['tar', 'tar.gz', 'tar.bz2', 'zip']; protected function configure(): void { $this ->setName('archive') ->setDescription('Creates an archive of this composer package') ->setDefinition([ new InputArgument('package', InputArgument::OPTIONAL, 'The package to archive instead of the current project', null, $this->suggestAvailablePackage()), new InputArgument('version', InputArgument::OPTIONAL, 'A version constraint to find the package to archive'), new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the resulting archive: tar, tar.gz, tar.bz2 or zip (default tar)', null, self::FORMATS), new InputOption('dir', null, InputOption::VALUE_REQUIRED, 'Write the archive to this directory'), new InputOption('file', null, InputOption::VALUE_REQUIRED, 'Write the archive with the given file name.' .' Note that the format will be appended.'), new InputOption('ignore-filters', null, InputOption::VALUE_NONE, 'Ignore filters when saving package'), ]) ->setHelp( "The archive command creates an archive of the specified format\ncontaining the files and directories of the Composer project or the specified\npackage in the specified version and writes it to the specified directory.\n\nphp composer.phar archive [--format=zip] [--dir=/foo] [--file=filename] [package [version]]\n\nRead more at https://getcomposer.org/doc/03-cli.md#archive" ) ; } protected function execute(InputInterface $input, OutputInterface $output): int { $composer = $this->tryComposer(); $config = null; if ($composer) { $config = $composer->getConfig(); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'archive', $input, $output); $eventDispatcher = $composer->getEventDispatcher(); $eventDispatcher->dispatch($commandEvent->getName(), $commandEvent); $eventDispatcher->dispatchScript(ScriptEvents::PRE_ARCHIVE_CMD); } if (!$config) { $config = Factory::createConfig(); } $format = $input->getOption('format') ?? $config->get('archive-format'); $dir = $input->getOption('dir') ?? $config->get('archive-dir'); $returnCode = $this->archive( $this->getIO(), $config, $input->getArgument('package'), $input->getArgument('version'), $format, $dir, $input->getOption('file'), $input->getOption('ignore-filters'), $composer ); if (0 === $returnCode && $composer) { $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ARCHIVE_CMD); } return $returnCode; } /** * @throws \Exception */ protected function archive( IOInterface $io, Config $config, ?string $packageName, ?string $version, string $format, string $dest, ?string $fileName, bool $ignoreFilters, ?Composer $composer, ): int { if ($composer) { $archiveManager = $composer->getArchiveManager(); } else { $factory = new Factory; $process = new ProcessExecutor(); $httpDownloader = Factory::createHttpDownloader($io, $config); $downloadManager = $factory->createDownloadManager($io, $config, $httpDownloader, $process); $archiveManager = $factory->createArchiveManager($config, $downloadManager, new Loop($httpDownloader, $process)); } if ($packageName) { $package = $this->selectPackage($io, $packageName, $version); if (!$package) { return 1; } } else { $package = $this->requireComposer()->getPackage(); } $io->writeError('Creating the archive into "'.$dest.'".'); $packagePath = $archiveManager->archive($package, $format, $dest, $fileName, $ignoreFilters); $fs = new Filesystem; $shortPath = $fs->findShortestPath(Platform::getCwd(), $packagePath, true); $io->writeError('Created: ', false); $io->write(strlen($shortPath) < strlen($packagePath) ? $shortPath : $packagePath); return 0; } /** * @return (BasePackage&CompletePackageInterface)|false */ protected function selectPackage(IOInterface $io, string $packageName, ?string $version = null) { $io->writeError('Searching for the specified package.'); if ($composer = $this->tryComposer()) { $localRepo = $composer->getRepositoryManager()->getLocalRepository(); $repo = new CompositeRepository(array_merge([$localRepo], $composer->getRepositoryManager()->getRepositories())); $minStability = $composer->getPackage()->getMinimumStability(); } else { $defaultRepos = RepositoryFactory::defaultReposWithDefaultManager($io); $io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos))); $repo = new CompositeRepository($defaultRepos); $minStability = 'stable'; } if ($version !== null && Preg::isMatchStrictGroups('{@(stable|RC|beta|alpha|dev)$}i', $version, $match)) { $minStability = $match[1]; $version = (string) substr($version, 0, -strlen($match[0])); } $repoSet = new RepositorySet($minStability); $repoSet->addRepository($repo); $parser = new VersionParser(); $constraint = $version !== null ? $parser->parseConstraints($version) : null; $packages = $repoSet->findPackages(strtolower($packageName), $constraint); if (count($packages) > 1) { $versionSelector = new VersionSelector($repoSet); $package = $versionSelector->findBestCandidate(strtolower($packageName), $version, $minStability); if ($package === false) { $package = reset($packages); } $io->writeError('Found multiple matches, selected '.$package->getPrettyString().'.'); $io->writeError('Alternatives were '.implode(', ', array_map(static function ($p): string { return $p->getPrettyString(); }, $packages)).'.'); $io->writeError('Please use a more specific constraint to pick a different package.'); } elseif (count($packages) === 1) { $package = reset($packages); $io->writeError('Found an exact match '.$package->getPrettyString().'.'); } else { $io->writeError('Could not find a package matching '.$packageName.'.'); return false; } if (!$package instanceof CompletePackageInterface) { throw new \LogicException('Expected a CompletePackageInterface instance but found '.get_class($package)); } if (!$package instanceof BasePackage) { throw new \LogicException('Expected a BasePackage instance but found '.get_class($package)); } return $package; } } __halt_compiler();----SIGNATURE:----Rh6uGrzz4cizMzrILZlbERB/5TF37NvwJxlUTGkvfo5WVmj4ZuuBD3xCbZi3v8W1mtUe8/cxkgjCNa4iIMDyh98IC41tyEGgGb+x/A/U2gWEXcf31GiyCQbsSsrXnNGOeKe0FeysrAPHZMZicspUgQDPuEDKjvhxlzFxzy9KdsZlGRS6JVgGUKPApsjeZrFZEiMYxzmabZX6OZJ6zcpnkeJjlHNLlbZqADi300FOHAmZ8YUiIei6ErZbTA1GpNdFKns2sEGWayXFzxQlFKJhX4WDlb+rlsCl/QkU9neIZFkdRpM8iz+OE4tBU27z8xPb3DN3c+KRxy1g54m2PvkcWgLJizAL77iPDwZl7/JIAJsMlx/XJFrO2k7qZbD2NgLB9xJngMae1Lpmj/WaDoXeMp6VB9LZdq6VD0hgBpg7x1LyqcWDTH82IoJlIlLccxUg/xEjESsnyyV009P1ElyGO49LtY90Cp0HBFBSMIJLA2QMjUMT3fTPJxSBTAfshl5fe9+42vK2NbpuwKusiE41iGxBjcPxcZeQucQ1+7QwUXGQxStbYG/ABdPDXgQ4/ym0k5ox+N7M7SQ2Gu/HKb0yg+5DfRfm6BooebmjBDwA8OVJICxDYM9TM2vCBA1qdqN4DssO7ppjWjVai3EkPmZbEjGxtEy6Y+yKrfZiiBvjd54=----ATTACHMENT:----MTU3MjYyMjc1NjA5MjAwOSA1MDM2OTg2OTExNjE5OTA5IDE2MDE1OTY1ODcyNzM0MjA=