本文整理汇总了PHP中Composer\Factory::createArchiveManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::createArchiveManager方法的具体用法?PHP Factory::createArchiveManager怎么用?PHP Factory::createArchiveManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Factory
的用法示例。
在下文中一共展示了Factory::createArchiveManager方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
$factory = new Factory();
$this->manager = $factory->createArchiveManager($factory->createConfig());
$this->targetDir = $this->testDir . '/composer_archiver_tests';
}
示例2: dump
/**
* Builds the archives of the repository.
*
* @param array $packages List of packages to dump
*/
public function dump(array $packages)
{
$helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
$directory = $helper->getDirectory($this->outputDir);
$this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
$format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
$endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
$includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
$composerConfig = Factory::createConfig();
$factory = new Factory();
$io = new ConsoleIO($this->input, $this->output, $this->helperSet);
$io->loadConfiguration($composerConfig);
/* @var \Composer\Downloader\DownloadManager $downloadManager */
$downloadManager = $factory->createDownloadManager($io, $composerConfig);
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
$archiveManager->setOverwriteFiles(false);
shuffle($packages);
/* @var \Composer\Package\CompletePackage $package */
foreach ($packages as $package) {
if ($helper->isSkippable($package)) {
continue;
}
$this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
try {
if ('pear-library' === $package->getType()) {
// PEAR packages are archives already
$filesystem = new Filesystem();
$packageName = $archiveManager->getPackageFilename($package);
$path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
if (!file_exists($path)) {
$downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
$filesystem->ensureDirectoryExists($downloadDir);
$downloadManager->download($package, $downloadDir, false);
$filesystem->ensureDirectoryExists($directory);
$filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
$filesystem->removeDirectory($downloadDir);
}
// Set archive format to `file` to tell composer to download it as is
$archiveFormat = 'file';
} else {
$path = $archiveManager->archive($package, $format, $directory);
$archiveFormat = $format;
}
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $this->config['archive']['directory'], $archive);
$package->setDistType($archiveFormat);
$package->setDistUrl($distUrl);
if ($includeArchiveChecksum) {
$package->setDistSha1Checksum(hash_file('sha1', $path));
}
$package->setDistReference($package->getSourceReference());
} catch (\Exception $exception) {
if (!$this->skipErrors) {
throw $exception;
}
$this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
}
}
示例3: archive
protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.')
{
$factory = new Factory();
$downloadManager = $factory->createDownloadManager($io, $config);
$archiveManager = $factory->createArchiveManager($config, $downloadManager);
if ($packageName) {
$package = $this->selectPackage($io, $packageName, $version);
if (!$package) {
return 1;
}
} else {
$package = $this->getComposer()->getPackage();
}
$io->writeError('<info>Creating the archive into "' . $dest . '".</info>');
$archiveManager->archive($package, $format, $dest);
return 0;
}
示例4: archive
protected function archive(IOInterface $io, Config $config, $packageName = null, $version = null, $format = 'tar', $dest = '.', $fileName = null)
{
$factory = new Factory();
$downloadManager = $factory->createDownloadManager($io, $config);
$archiveManager = $factory->createArchiveManager($config, $downloadManager);
if ($packageName) {
$package = $this->selectPackage($io, $packageName, $version);
if (!$package) {
return 1;
}
} else {
$package = $this->getComposer()->getPackage();
}
$io->writeError('<info>Creating the archive into "' . $dest . '".</info>');
$packagePath = $archiveManager->archive($package, $format, $dest, $fileName);
$fs = new Filesystem();
$shortPath = $fs->findShortestPath(getcwd(), $packagePath, true);
$io->writeError('Created: ', false);
$io->write(strlen($shortPath) < strlen($packagePath) ? $shortPath : $packagePath);
return 0;
}
示例5: dumpDownloads
/**
* @param array $config Directory where to create the downloads in, prefix-url, etc..
* @param array $packages Reference to packages so we can rewrite the JSON.
* @param OutputInterface $output
* @param string $outputDir
* @param bool $skipErrors If true, any exception while dumping a package will be ignored.
*
* @return void
*/
private function dumpDownloads(array $config, array &$packages, OutputInterface $output, $outputDir, $skipErrors)
{
if (isset($config['archive']['absolute-directory'])) {
$directory = $config['archive']['absolute-directory'];
} else {
$directory = sprintf('%s/%s', $outputDir, $config['archive']['directory']);
}
$output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
$format = isset($config['archive']['format']) ? $config['archive']['format'] : 'zip';
$endpoint = isset($config['archive']['prefix-url']) ? $config['archive']['prefix-url'] : $config['homepage'];
$skipDev = isset($config['archive']['skip-dev']) ? (bool) $config['archive']['skip-dev'] : false;
$whitelist = isset($config['archive']['whitelist']) ? (array) $config['archive']['whitelist'] : array();
$blacklist = isset($config['archive']['blacklist']) ? (array) $config['archive']['blacklist'] : array();
$composerConfig = Factory::createConfig();
$factory = new Factory();
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig);
$archiveManager->setOverwriteFiles(false);
/* @var \Composer\Package\CompletePackage $package */
foreach ($packages as $name => $package) {
if (true === $skipDev && true === $package->isDev()) {
$output->writeln(sprintf("<info>Skipping '%s' (is dev)</info>", $name));
continue;
}
$names = $package->getNames();
if ($whitelist && !array_intersect($whitelist, $names)) {
$output->writeln(sprintf("<info>Skipping '%s' (is not in whitelist)</info>", $name));
continue;
}
if ($blacklist && array_intersect($blacklist, $names)) {
$output->writeln(sprintf("<info>Skipping '%s' (is in blacklist)</info>", $name));
continue;
}
$output->writeln(sprintf("<info>Dumping '%s'.</info>", $name));
try {
$path = $archiveManager->archive($package, $format, $directory);
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $config['archive']['directory'], $archive);
$package->setDistType($format);
$package->setDistUrl($distUrl);
$package->setDistSha1Checksum(hash_file('sha1', $path));
$package->setDistReference($package->getSourceReference());
} catch (\Exception $exception) {
if (!$skipErrors) {
throw $exception;
}
$output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
}
}
示例6: dumpDownloads
/**
* @param array $config Directory where to create the downloads in, prefix-url, etc..
* @param array $packages
* @param InputInterface $input
* @param OutputInterface $output
* @param string $outputDir
* @param bool $skipErrors If true, any exception while dumping a package will be ignored.
*
* @return void
*/
private function dumpDownloads(array $config, array $packages, InputInterface $input, OutputInterface $output, $outputDir, $skipErrors)
{
if (isset($config['archive']['absolute-directory'])) {
$directory = $config['archive']['absolute-directory'];
} else {
$directory = sprintf('%s/%s', $outputDir, $config['archive']['directory']);
}
$output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $directory));
$format = isset($config['archive']['format']) ? $config['archive']['format'] : 'zip';
$endpoint = isset($config['archive']['prefix-url']) ? $config['archive']['prefix-url'] : $config['homepage'];
$skipDev = isset($config['archive']['skip-dev']) ? (bool) $config['archive']['skip-dev'] : false;
$whitelist = isset($config['archive']['whitelist']) ? (array) $config['archive']['whitelist'] : array();
$blacklist = isset($config['archive']['blacklist']) ? (array) $config['archive']['blacklist'] : array();
$includeArchiveChecksum = isset($config['archive']['checksum']) ? (bool) $config['archive']['checksum'] : true;
$composerConfig = Factory::createConfig();
$factory = new Factory();
$io = new ConsoleIO($input, $output, $this->getApplication()->getHelperSet());
$io->loadConfiguration($composerConfig);
/* @var \Composer\Downloader\DownloadManager $downloadManager */
$downloadManager = $factory->createDownloadManager($io, $composerConfig);
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
$archiveManager->setOverwriteFiles(false);
shuffle($packages);
/* @var \Composer\Package\CompletePackage $package */
foreach ($packages as $package) {
if ('metapackage' === $package->getType()) {
continue;
}
$name = $package->getName();
if (true === $skipDev && true === $package->isDev()) {
$output->writeln(sprintf("<info>Skipping '%s' (is dev)</info>", $name));
continue;
}
$names = $package->getNames();
if ($whitelist && !array_intersect($whitelist, $names)) {
$output->writeln(sprintf("<info>Skipping '%s' (is not in whitelist)</info>", $name));
continue;
}
if ($blacklist && array_intersect($blacklist, $names)) {
$output->writeln(sprintf("<info>Skipping '%s' (is in blacklist)</info>", $name));
continue;
}
$output->writeln(sprintf("<info>Dumping '%s'.</info>", $name));
try {
if ('pear-library' === $package->getType()) {
// PEAR packages are archives already
$filesystem = new Filesystem();
$packageName = $archiveManager->getPackageFilename($package);
$path = realpath($directory) . '/' . $packageName . '.' . pathinfo($package->getDistUrl(), PATHINFO_EXTENSION);
if (!file_exists($path)) {
$downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
$filesystem->ensureDirectoryExists($downloadDir);
$downloadManager->download($package, $downloadDir, false);
$filesystem->ensureDirectoryExists($directory);
$filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
$filesystem->removeDirectory($downloadDir);
}
// Set archive format to `file` to tell composer to download it as is
$archiveFormat = 'file';
} else {
$path = $archiveManager->archive($package, $format, $directory);
$archiveFormat = $format;
}
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s', $endpoint, $config['archive']['directory'], $archive);
$package->setDistType($archiveFormat);
$package->setDistUrl($distUrl);
if ($includeArchiveChecksum) {
$package->setDistSha1Checksum(hash_file('sha1', $path));
}
$package->setDistReference($package->getSourceReference());
} catch (\Exception $exception) {
if (!$skipErrors) {
throw $exception;
}
$output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
}
}
示例7: dump
/**
* {@inheritdoc}
*/
public function dump(array $packages)
{
$helper = new ArchiveBuilderHelper($this->output, $this->config['archive']);
$basedir = $helper->getDirectory($this->outputDir);
$this->output->writeln(sprintf("<info>Creating local downloads in '%s'</info>", $basedir));
$format = isset($this->config['archive']['format']) ? $this->config['archive']['format'] : 'zip';
$endpoint = isset($this->config['archive']['prefix-url']) ? $this->config['archive']['prefix-url'] : $this->config['homepage'];
$includeArchiveChecksum = isset($this->config['archive']['checksum']) ? (bool) $this->config['archive']['checksum'] : true;
$composerConfig = $this->composer->getConfig();
$factory = new Factory();
/* @var \Composer\Downloader\DownloadManager $downloadManager */
$downloadManager = $this->composer->getDownloadManager();
/* @var \Composer\Package\Archiver\ArchiveManager $archiveManager */
$archiveManager = $factory->createArchiveManager($composerConfig, $downloadManager);
$archiveManager->setOverwriteFiles(false);
shuffle($packages);
$progressBar = null;
$hasStarted = false;
$verbosity = $this->output->getVerbosity();
$renderProgress = $this->input->getOption('stats') && OutputInterface::VERBOSITY_NORMAL == $verbosity;
if ($renderProgress) {
$packageCount = 0;
foreach ($packages as $package) {
if (!$helper->isSkippable($package)) {
++$packageCount;
}
}
$progressBar = new ProgressBar($this->output, $packageCount);
$progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% - Installing %packageName% (%packageVersion%)');
}
/* @var \Composer\Package\CompletePackage $package */
foreach ($packages as $package) {
if ($helper->isSkippable($package)) {
continue;
}
if ($renderProgress) {
$progressBar->setMessage($package->getName(), 'packageName');
$progressBar->setMessage($package->getPrettyVersion(), 'packageVersion');
if (!$hasStarted) {
$progressBar->start();
$hasStarted = true;
} else {
$progressBar->display();
}
} else {
$this->output->writeln(sprintf("<info>Dumping '%s'.</info>", $package->getName()));
}
try {
if ($renderProgress) {
$this->output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
$intermediatePath = preg_replace('#[^a-z0-9-_/]#i', '-', $package->getName());
$packageName = $archiveManager->getPackageFilename($package);
if ('pear-library' === $package->getType()) {
// PEAR packages are archives already
$filesystem = new Filesystem();
$path = sprintf('%s/%s/%s.%s', realpath($basedir), $intermediatePath, $packageName, pathinfo($package->getDistUrl(), PATHINFO_EXTENSION));
if (!file_exists($path)) {
$downloadDir = sys_get_temp_dir() . '/composer_archiver/' . $packageName;
$filesystem->ensureDirectoryExists($downloadDir);
$downloadManager->download($package, $downloadDir, false);
$filesystem->ensureDirectoryExists(dirname($path));
$filesystem->rename($downloadDir . '/' . pathinfo($package->getDistUrl(), PATHINFO_BASENAME), $path);
$filesystem->removeDirectory($downloadDir);
}
// Set archive format to `file` to tell composer to download it as is
$archiveFormat = 'file';
} else {
$path = $archiveManager->archive($package, $format, sprintf('%s/%s', $basedir, $intermediatePath));
$archiveFormat = $format;
}
$archive = basename($path);
$distUrl = sprintf('%s/%s/%s/%s', $endpoint, $this->config['archive']['directory'], $intermediatePath, $archive);
$package->setDistType($archiveFormat);
$package->setDistUrl($distUrl);
if ($includeArchiveChecksum) {
$package->setDistSha1Checksum(hash_file('sha1', $path));
}
$package->setDistReference($package->getSourceReference());
if ($renderProgress) {
$this->output->setVerbosity($verbosity);
}
} catch (\Exception $exception) {
if ($renderProgress) {
$this->output->setVerbosity($verbosity);
}
if (!$this->skipErrors) {
throw $exception;
}
$this->output->writeln(sprintf("<error>Skipping Exception '%s'.</error>", $exception->getMessage()));
}
if ($renderProgress) {
$progressBar->advance();
}
}
if ($renderProgress) {
$progressBar->finish();
//.........这里部分代码省略.........