/** * 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())); } } }
/** * Get the Composer instance. * * @param bool $required * @param array|string|null $config * @return Composer\Composer */ public function getComposer($required = true, $config = null) { if (is_null($this->composer)) { try { $this->composer = Factory::create($this->consoleIo, $config); } catch (\InvalidArgumentException $e) { $this->consoleIo->write($e->getMessage()); exit(1); } } return $this->composer; }
/** * @return \Composer\Composer */ public function getComposer() { if ($this->composer === NULL) { try { $this->composer = Factory::create($this->io, NULL, FALSE); } catch (\InvalidArgumentException $e) { $this->io->writeError($e->getMessage()); exit(1); } catch (\Composer\Json\JsonValidationException $e) { $errors = ' - ' . implode(PHP_EOL . ' - ', $e->getErrors()); $message = $e->getMessage() . ':' . PHP_EOL . $errors; throw new \Composer\Json\JsonValidationException($message); } } return $this->composer; }
/** * @param string $input * @param int $verbosity * @param OutputFormatterInterface|null $formatter */ public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null) { $input = new StringInput($input); $input->setInteractive(false); $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity, $formatter ? $formatter->isDecorated() : false, $formatter); parent::__construct($input, $output, new HelperSet(array())); }
public static function migrateDatabase(Event $event = null, $testing = false) { if ($event) { // Use the event's IO $io = $event->getIO(); $arguments = $event->getArguments(); $testingArguments = array('testing', '--testing', '-t'); $testing = count(array_intersect($arguments, $testingArguments)) > 0; } else { // Create our own IO $input = new ArrayInput(array()); $output = new ConsoleOutput(); $helperSet = new HelperSet(array(new QuestionHelper())); $io = new ConsoleIO($input, $output, $helperSet); } try { $config = self::getDatabaseConfig($testing); } catch (\Exception $e) { $io->write("<bg=red>\n\n [WARNING] " . $e->getMessage() . ", the database won't be updated\n</>"); return; } // If the database doesn't exist, ask the user to create it and perform // the necessary migrations (unless the user didn't agree to // create the database) if (self::createDatabase($io, $config['host'], $config['username'], $config['password'], $config['database'])) { $io->write(''); // newline $arguments = array('migrate', '-e' => $testing ? 'test' : 'main'); $app = new PhinxApplication(); $app->doRun(new ArrayInput($arguments), new ConsoleOutput()); } }
/** * {@inheritdoc} */ public function writeError($messages, $newline = true) { foreach ((array) $messages as $message) { if (preg_match(self::REGEX, $message, $matches)) { throw new \RuntimeException($matches[0]); } } parent::writeError($messages, $newline); }
public function testhasAuthentication() { $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'); $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $helperMock = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet'); $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); $consoleIO->setAuthentication('repoName', 'l3l0', 'passwd'); $this->assertTrue($consoleIO->hasAuthentication('repoName')); $this->assertFalse($consoleIO->hasAuthentication('repoName2')); }
/** * @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())); } } }
public function testGetLastPassword() { $inputMock = $this->getMock('Symfony\\Component\\Console\\Input\\InputInterface'); $outputMock = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface'); $helperMock = $this->getMock('Symfony\\Component\\Console\\Helper\\HelperSet'); $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); $consoleIO->setAuthorization('repoName', 'l3l0', 'passwd'); $consoleIO->setAuthorization('repoName2', 'l3l02', 'passwd2'); $this->assertEquals('passwd2', $consoleIO->getLastPassword()); }