/** * @param InputInterface $input The input instance * @param OutputInterface $output The output instance */ protected function execute(InputInterface $input, OutputInterface $output) { $verbose = $input->getOption('verbose'); $configFile = $input->getArgument('file'); $packagesFilter = $input->getArgument('packages'); $repositoryUrl = $input->getOption('repository-url'); $skipErrors = (bool) $input->getOption('skip-errors'); if ($repositoryUrl !== null && count($packagesFilter) > 0) { throw new \InvalidArgumentException('The arguments "package" and "repository-url" can not be used together.'); } // load auth.json authentication information and pass it to the io interface $io = $this->getIO(); $io->loadConfiguration($this->getConfiguration()); if (preg_match('{^https?://}i', $configFile)) { $rfs = new RemoteFilesystem($io); $contents = $rfs->getContents(parse_url($configFile, PHP_URL_HOST), $configFile, false); $config = JsonFile::parseJson($contents, $configFile); } else { $file = new JsonFile($configFile); if (!$file->exists()) { $output->writeln('<error>File not found: ' . $configFile . '</error>'); return 1; } $config = $file->read(); } // disable packagist by default unset(Config::$defaultRepositories['packagist']); if (!($outputDir = $input->getArgument('output-dir'))) { $outputDir = isset($config['output-dir']) ? $config['output-dir'] : null; } if (null === $outputDir) { throw new \InvalidArgumentException('The output dir must be specified as second argument or be configured inside ' . $input->getArgument('file')); } $composer = $this->getApplication()->getComposer(true, $config); $packageSelection = new PackageSelection($output, $outputDir, $config, $skipErrors); if ($repositoryUrl !== null) { $packageSelection->setRepositoryFilter($repositoryUrl); } else { $packageSelection->setPackagesFilter($packagesFilter); } $packages = $packageSelection->select($composer, $verbose); if (isset($config['archive']['directory'])) { $downloads = new ArchiveBuilder($output, $outputDir, $config, $skipErrors); $downloads->setComposer($composer); $downloads->dump($packages); } if ($packageSelection->hasFilterForPackages()) { // in case of an active package filter we need to load the dumped packages.json and merge the // updated packages in $oldPackages = $packageSelection->load(); $packages += $oldPackages; ksort($packages); } $packagesBuilder = new PackagesBuilder($output, $outputDir, $config, $skipErrors); $packagesBuilder->dump($packages); if ($htmlView = !$input->getOption('no-html-output')) { $htmlView = !isset($config['output-html']) || $config['output-html']; } if ($htmlView) { $web = new WebBuilder($output, $outputDir, $config, $skipErrors); $web->setRootPackage($composer->getPackage()); $web->dump($packages); } }