本文整理汇总了PHP中Composer\Factory::createDefaultRepositories方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::createDefaultRepositories方法的具体用法?PHP Factory::createDefaultRepositories怎么用?PHP Factory::createDefaultRepositories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Factory
的用法示例。
在下文中一共展示了Factory::createDefaultRepositories方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectPackage
protected function selectPackage(IOInterface $io, $packageName, $version = null)
{
$io->writeError('<info>Searching for the specified package.</info>');
if ($composer = $this->getComposer(false)) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$io->writeError('No composer.json found in the current directory, searching packages from ' . implode(', ', array_keys($defaultRepos)));
$repos = new CompositeRepository($defaultRepos);
}
$pool = new Pool();
$pool->addRepository($repos);
$parser = new VersionParser();
$constraint = $version ? $parser->parseConstraints($version) : null;
$packages = $pool->whatProvides($packageName, $constraint, true);
if (count($packages) > 1) {
$package = reset($packages);
$io->writeError('<info>Found multiple matches, selected ' . $package->getPrettyString() . '.</info>');
$io->writeError('Alternatives were ' . implode(', ', array_map(function ($p) {
return $p->getPrettyString();
}, $packages)) . '.');
$io->writeError('<comment>Please use a more specific constraint to pick a different package.</comment>');
} elseif ($packages) {
$package = reset($packages);
$io->writeError('<info>Found an exact match ' . $package->getPrettyString() . '.</info>');
} else {
$io->writeError('<error>Could not find a package matching ' . $packageName . '.</error>');
return false;
}
return $package;
}
示例2: execute
/**
* Search for packages.
*
* @param array $packages Indexed array of package names to search for
* @param boolean $onlyname True for name only search, false for full text
*
* @throws PackageManagerException
*
* @return array List of matching packages
*/
public function execute($packages, $onlyname = true)
{
/** @var $composer \Composer\Composer */
$composer = $this->getComposer();
$io = $this->getIO();
$platformRepo = new PlatformRepository();
if ($composer) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository([$localRepo, $platformRepo]);
$repos = new CompositeRepository(array_merge([$installedRepo], $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($io);
//No composer.json found in the current directory, showing packages from local repo
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge([$installedRepo], $defaultRepos));
}
$flags = $onlyname ? RepositoryInterface::SEARCH_NAME : RepositoryInterface::SEARCH_FULLTEXT;
try {
return $repos->search(implode(' ', $packages), $flags);
} catch (\Exception $e) {
$msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
$this->app['logger.system']->critical($msg, ['event' => 'exception', 'exception' => $e]);
throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
}
}
示例3: getPackagistRepository
/**
*
* @return ComposerRepository
*/
private function getPackagistRepository()
{
if (!$this->repos) {
$this->repos = Factory::createDefaultRepositories($this->getIO());
}
return $this->repos['packagist'];
}
示例4: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// init repos
$platformRepo = new PlatformRepository();
if ($composer = $this->getComposer(false)) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$output->writeln('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'search', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
}
$onlyName = $input->getOption('only-name');
$flags = $onlyName ? RepositoryInterface::SEARCH_NAME : RepositoryInterface::SEARCH_FULLTEXT;
$results = $repos->search(implode(' ', $input->getArgument('tokens')), $flags);
foreach ($results as $result) {
$output->writeln($result['name'] . (isset($result['description']) ? ' ' . $result['description'] : ''));
}
}
示例5: installProject
public function installProject(IOInterface $io, $packageName, $directory = null, $version = null, $preferSource = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false)
{
$dm = $this->createDownloadManager($io);
if ($preferSource) {
$dm->setPreferSource(true);
}
$config = Factory::createConfig();
if (null === $repositoryUrl) {
$sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
$sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
} elseif (0 === strpos($repositoryUrl, 'http')) {
$sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
} else {
throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
}
$candidates = $sourceRepo->findPackages($packageName, $version);
if (!$candidates) {
throw new \InvalidArgumentException("Could not find package {$packageName}" . ($version ? " with version {$version}." : ''));
}
if (null === $directory) {
$parts = explode("/", $packageName, 2);
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
}
// select highest version if we have many
$package = $candidates[0];
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
$io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>', true);
if ($disableCustomInstallers) {
$io->write('<info>Custom installers have been disabled.</info>');
}
if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
$package->setSourceReference(substr($package->getPrettyVersion(), 4));
}
$projectInstaller = new ProjectInstaller($directory, $dm);
$projectInstaller->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), $package);
if ($package->getRepository() instanceof NotifiableRepositoryInterface) {
$package->getRepository()->notifyInstall($package);
}
$io->write('<info>Created project in ' . $directory . '</info>', true);
chdir($directory);
putenv('COMPOSER_ROOT_VERSION=' . $package->getPrettyVersion());
$composer = Factory::create($io);
$installer = Installer::create($io, $composer);
$installer->setPreferSource($preferSource)->setDevMode($installDevPackages)->setRunScripts(!$noScripts);
if ($disableCustomInstallers) {
$installer->disableCustomInstallers();
}
$installer->run();
}
示例6: load
public function load(array $config, $class = 'Composer\\Package\\RootPackage')
{
if (!isset($config['name'])) {
$config['name'] = '__root__';
}
if (!isset($config['version'])) {
if (getenv('COMPOSER_ROOT_VERSION')) {
$version = getenv('COMPOSER_ROOT_VERSION');
} else {
$version = $this->guessVersion($config);
}
if (!$version) {
$version = '1.0.0';
}
$config['version'] = $version;
}
$realPackage = $package = parent::load($config, $class);
if ($realPackage instanceof AliasPackage) {
$realPackage = $package->getAliasOf();
}
if (isset($config['minimum-stability'])) {
$realPackage->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
}
$aliases = array();
$stabilityFlags = array();
$references = array();
foreach (array('require', 'require-dev') as $linkType) {
if (isset($config[$linkType])) {
$linkInfo = BasePackage::$supportedLinkTypes[$linkType];
$method = 'get' . ucfirst($linkInfo['method']);
$links = array();
foreach ($realPackage->{$method}() as $link) {
$links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
}
$aliases = $this->extractAliases($links, $aliases);
$stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
$references = $this->extractReferences($links, $references);
}
}
$realPackage->setAliases($aliases);
$realPackage->setStabilityFlags($stabilityFlags);
$realPackage->setReferences($references);
if (isset($config['prefer-stable'])) {
$realPackage->setPreferStable((bool) $config['prefer-stable']);
}
$repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
foreach ($repos as $repo) {
$this->manager->addRepository($repo);
}
$realPackage->setRepositories($this->config->getRepositories());
return $package;
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// init repos
$platformRepo = new PlatformRepository();
if ($composer = $this->getComposer(false)) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$output->writeln('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
$tokens = $input->getArgument('tokens');
$packages = array();
$maxPackageLength = 0;
foreach ($repos->getPackages() as $package) {
if ($package instanceof AliasPackage || isset($packages[$package->getName()])) {
continue;
}
foreach ($tokens as $token) {
if (!($score = $this->matchPackage($package, $token))) {
continue;
}
if (false !== ($pos = stripos($package->getName(), $token))) {
$name = substr($package->getPrettyName(), 0, $pos) . '<highlight>' . substr($package->getPrettyName(), $pos, strlen($token)) . '</highlight>' . substr($package->getPrettyName(), $pos + strlen($token));
} else {
$name = $package->getPrettyName();
}
$description = strtok($package->getDescription(), "\r\n");
if (false !== ($pos = stripos($description, $token))) {
$description = substr($description, 0, $pos) . '<highlight>' . substr($description, $pos, strlen($token)) . '</highlight>' . substr($description, $pos + strlen($token));
}
$packages[$package->getName()] = array('name' => $name, 'description' => $description, 'length' => $length = strlen($package->getPrettyName()), 'score' => $score);
$maxPackageLength = max($maxPackageLength, $length);
continue 2;
}
}
usort($packages, function ($a, $b) {
if ($a['score'] === $b['score']) {
return 0;
}
return $a['score'] > $b['score'] ? -1 : 1;
});
foreach ($packages as $details) {
$extraSpaces = $maxPackageLength - $details['length'];
$output->writeln($details['name'] . str_repeat(' ', $extraSpaces) . ' <comment>:</comment> ' . $details['description']);
}
}
示例8: load
public function load($config)
{
if (!isset($config['name'])) {
$config['name'] = '__root__';
}
if (!isset($config['version'])) {
// override with env var if available
if (getenv('COMPOSER_ROOT_VERSION')) {
$version = getenv('COMPOSER_ROOT_VERSION');
} else {
$version = $this->guessVersion($config);
}
if (!$version) {
$version = '1.0.0';
}
$config['version'] = $version;
} else {
$version = $config['version'];
}
$package = parent::load($config);
$aliases = array();
$stabilityFlags = array();
$references = array();
foreach (array('require', 'require-dev') as $linkType) {
if (isset($config[$linkType])) {
$aliases = $this->extractAliases($config[$linkType], $aliases);
$stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
$references = $this->extractReferences($config[$linkType], $references);
}
}
$package->setAliases($aliases);
$package->setStabilityFlags($stabilityFlags);
$package->setReferences($references);
if (isset($config['minimum-stability'])) {
$package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
}
$repos = Factory::createDefaultRepositories(null, $this->config, $this->manager);
foreach ($repos as $repo) {
$this->manager->addRepository($repo);
}
$package->setRepositories($this->config->getRepositories());
return $package;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// init repos
$platformRepo = new PlatformRepository();
if ($composer = $this->getComposer(false)) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$output->writeln('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
$this->tokens = $input->getArgument('tokens');
$this->output = $output;
$repos->filterPackages(array($this, 'processPackage'), 'Composer\\Package\\CompletePackage');
foreach ($this->lowMatches as $details) {
$output->writeln($details['name'] . '<comment>:</comment> ' . $details['description']);
}
}
示例10: installRootPackage
protected function installRootPackage(IOInterface $io, $config, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disablePlugins = false, $noScripts = false, $keepVcs = false, $noProgress = false)
{
if (null === $repositoryUrl) {
$sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
$sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
} elseif (0 === strpos($repositoryUrl, 'http')) {
$sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
} else {
throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
}
$parser = new VersionParser();
$candidates = array();
$requirements = $parser->parseNameVersionPairs(array($packageName));
$name = strtolower($requirements[0]['name']);
if (!$packageVersion && isset($requirements[0]['version'])) {
$packageVersion = $requirements[0]['version'];
}
if (null === $stability) {
if (preg_match('{^[^,\\s]*?@(' . implode('|', array_keys(BasePackage::$stabilities)) . ')$}i', $packageVersion, $match)) {
$stability = $match[1];
} else {
$stability = VersionParser::parseStability($packageVersion);
}
}
$stability = VersionParser::normalizeStability($stability);
if (!isset(BasePackage::$stabilities[$stability])) {
throw new \InvalidArgumentException('Invalid stability provided (' . $stability . '), must be one of: ' . implode(', ', array_keys(BasePackage::$stabilities)));
}
$pool = new Pool($stability);
$pool->addRepository($sourceRepo);
$constraint = $packageVersion ? $parser->parseConstraints($packageVersion) : null;
$candidates = $pool->whatProvides($name, $constraint);
foreach ($candidates as $key => $candidate) {
if ($candidate->getName() !== $name) {
unset($candidates[$key]);
}
}
if (!$candidates) {
throw new \InvalidArgumentException("Could not find package {$name}" . ($packageVersion ? " with version {$packageVersion}." : " with stability {$stability}."));
}
if (null === $directory) {
$parts = explode("/", $name, 2);
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
}
$package = reset($candidates);
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
unset($candidates);
$io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>');
if ($disablePlugins) {
$io->write('<info>Plugins have been disabled.</info>');
}
if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
$package->setSourceReference(substr($package->getPrettyVersion(), 4));
}
$dm = $this->createDownloadManager($io, $config);
$dm->setPreferSource($preferSource)->setPreferDist($preferDist)->setOutputProgress(!$noProgress);
$projectInstaller = new ProjectInstaller($directory, $dm);
$im = $this->createInstallationManager();
$im->addInstaller($projectInstaller);
$im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
$im->notifyInstalls();
$installedFromVcs = 'source' === $package->getInstallationSource();
$io->write('<info>Created project in ' . $directory . '</info>');
chdir($directory);
putenv('COMPOSER_ROOT_VERSION=' . $package->getPrettyVersion());
return $installedFromVcs;
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->versionParser = new VersionParser();
// init repos
$platformRepo = new PlatformRepository();
$composer = $this->getComposer(false);
if ($input->getOption('self')) {
$package = $this->getComposer()->getPackage();
$repos = $installedRepo = new ArrayRepository(array($package));
} elseif ($input->getOption('platform')) {
$repos = $installedRepo = $platformRepo;
} elseif ($input->getOption('installed')) {
$repos = $installedRepo = $this->getComposer()->getRepositoryManager()->getLocalRepository();
} elseif ($input->getOption('available')) {
$installedRepo = $platformRepo;
if ($composer) {
$repos = new CompositeRepository($composer->getRepositoryManager()->getRepositories());
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$repos = new CompositeRepository($defaultRepos);
$output->writeln('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
}
} elseif ($composer) {
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$output->writeln('No composer.json found in the current directory, showing available packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'show', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
}
// show single package or single version
if ($input->getArgument('package') || !empty($package)) {
$versions = array();
if (empty($package)) {
list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
if (!$package) {
throw new \InvalidArgumentException('Package ' . $input->getArgument('package') . ' not found');
}
} else {
$versions = array($package->getPrettyVersion() => $package->getVersion());
}
$this->printMeta($input, $output, $package, $versions, $installedRepo, $repos);
$this->printLinks($input, $output, $package, 'requires');
$this->printLinks($input, $output, $package, 'devRequires', 'requires (dev)');
if ($package->getSuggests()) {
$output->writeln("\n<info>suggests</info>");
foreach ($package->getSuggests() as $suggested => $reason) {
$output->writeln($suggested . ' <comment>' . $reason . '</comment>');
}
}
$this->printLinks($input, $output, $package, 'provides');
$this->printLinks($input, $output, $package, 'conflicts');
$this->printLinks($input, $output, $package, 'replaces');
return;
}
// list packages
$packages = array();
if ($repos instanceof CompositeRepository) {
$repos = $repos->getRepositories();
} elseif (!is_array($repos)) {
$repos = array($repos);
}
foreach ($repos as $repo) {
if ($repo === $platformRepo) {
$type = '<info>platform</info>:';
} elseif ($repo === $installedRepo || $installedRepo instanceof CompositeRepository && in_array($repo, $installedRepo->getRepositories(), true)) {
$type = '<info>installed</info>:';
} else {
$type = '<comment>available</comment>:';
}
if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
foreach ($repo->getProviderNames() as $name) {
$packages[$type][$name] = $name;
}
} else {
foreach ($repo->getPackages() as $package) {
if (!isset($packages[$type][$package->getName()]) || !is_object($packages[$type][$package->getName()]) || version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')) {
$packages[$type][$package->getName()] = $package;
}
}
}
}
$tree = !$input->getOption('platform') && !$input->getOption('installed') && !$input->getOption('available');
$indent = $tree ? ' ' : '';
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
if (isset($packages[$type])) {
if ($tree) {
$output->writeln($type);
}
ksort($packages[$type]);
$nameLength = $versionLength = 0;
foreach ($packages[$type] as $package) {
if (is_object($package)) {
$nameLength = max($nameLength, strlen($package->getPrettyName()));
//.........这里部分代码省略.........
示例12: findPackages
protected function findPackages($name)
{
$packages = array();
// init repos
if (!$this->repos) {
$this->repos = new CompositeRepository(array_merge(array(new PlatformRepository()), Factory::createDefaultRepositories($this->getIO())));
}
$token = strtolower($name);
$this->repos->filterPackages(function ($package) use($token, &$packages) {
if (false !== strpos($package->getName(), $token)) {
$packages[] = $package;
}
});
return $packages;
}
示例13: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// init repos
$platformRepo = new PlatformRepository();
$getRepositories = function (Composer $composer, $dev) {
$manager = $composer->getRepositoryManager();
$repos = new CompositeRepository(array($manager->getLocalRepository()));
if ($dev) {
$repos->addRepository($manager->getLocalDevRepository());
}
return $repos;
};
if ($input->getOption('self')) {
$package = $this->getComposer(false)->getPackage();
$repos = $installedRepo = new ArrayRepository(array($package));
} elseif ($input->getOption('platform')) {
$repos = $installedRepo = $platformRepo;
} elseif ($input->getOption('installed')) {
$repos = $installedRepo = $getRepositories($this->getComposer(), $input->getOption('dev'));
} elseif ($composer = $this->getComposer(false)) {
$localRepo = $getRepositories($composer, $input->getOption('dev'));
$installedRepo = new CompositeRepository(array($localRepo, $platformRepo));
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
} else {
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
$output->writeln('No composer.json found in the current directory, showing packages from ' . implode(', ', array_keys($defaultRepos)));
$installedRepo = $platformRepo;
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
}
// show single package or single version
if ($input->getArgument('package') || !empty($package)) {
$versions = array();
if (empty($package)) {
list($package, $versions) = $this->getPackage($installedRepo, $repos, $input->getArgument('package'), $input->getArgument('version'));
if (!$package) {
throw new \InvalidArgumentException('Package ' . $input->getArgument('package') . ' not found');
}
} else {
$versions = array($package->getPrettyVersion() => $package->getVersion());
}
$this->printMeta($input, $output, $package, $versions, $installedRepo, $repos);
$this->printLinks($input, $output, $package, 'requires');
$this->printLinks($input, $output, $package, 'devRequires', 'requires (dev)');
if ($package->getSuggests()) {
$output->writeln("\n<info>suggests</info>");
foreach ($package->getSuggests() as $suggested => $reason) {
$output->writeln($suggested . ' <comment>' . $reason . '</comment>');
}
}
$this->printLinks($input, $output, $package, 'provides');
$this->printLinks($input, $output, $package, 'conflicts');
$this->printLinks($input, $output, $package, 'replaces');
return;
}
// list packages
$packages = array();
$repos->filterPackages(function ($package) use(&$packages, $platformRepo, $installedRepo) {
if ($platformRepo->hasPackage($package)) {
$type = '<info>platform</info>:';
} elseif ($installedRepo->hasPackage($package)) {
$type = '<info>installed</info>:';
} else {
$type = '<comment>available</comment>:';
}
if (!isset($packages[$type][$package->getName()]) || version_compare($packages[$type][$package->getName()]->getVersion(), $package->getVersion(), '<')) {
$packages[$type][$package->getName()] = $package;
}
}, 'Composer\\Package\\CompletePackage');
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
if (isset($packages[$type])) {
$output->writeln($type);
ksort($packages[$type]);
foreach ($packages[$type] as $package) {
$output->writeln(' ' . $package->getPrettyName() . ' ' . ($showVersion ? '[' . $package->getPrettyVersion() . ']' : '') . ' <comment>:</comment> ' . strtok($package->getDescription(), "\r\n"));
}
$output->writeln('');
}
}
}
示例14: initializeRepos
/**
* Initializes repositories
*
* Returns an array of repos in order they should be checked in
*
* @return RepositoryInterface[]
*/
private function initializeRepos()
{
$composer = $this->getComposer(false);
if ($composer) {
return array($composer->getRepositoryManager()->getLocalRepository(), new CompositeRepository($composer->getRepositoryManager()->getRepositories()));
}
$defaultRepos = Factory::createDefaultRepositories($this->getIO());
return array(new CompositeRepository($defaultRepos));
}
示例15: installProject
public function installProject(IOInterface $io, $packageName, $directory = null, $packageVersion = null, $stability = 'stable', $preferSource = false, $preferDist = false, $installDevPackages = false, $repositoryUrl = null, $disableCustomInstallers = false, $noScripts = false, $keepVcs = false)
{
$config = Factory::createConfig();
$stability = strtolower($stability);
if ($stability === 'rc') {
$stability = 'RC';
}
if (!isset(BasePackage::$stabilities[$stability])) {
throw new \InvalidArgumentException('Invalid stability provided (' . $stability . '), must be one of: ' . implode(', ', array_keys(BasePackage::$stabilities)));
}
if (null === $repositoryUrl) {
$sourceRepo = new CompositeRepository(Factory::createDefaultRepositories($io, $config));
} elseif ("json" === pathinfo($repositoryUrl, PATHINFO_EXTENSION)) {
$sourceRepo = new FilesystemRepository(new JsonFile($repositoryUrl, new RemoteFilesystem($io)));
} elseif (0 === strpos($repositoryUrl, 'http')) {
$sourceRepo = new ComposerRepository(array('url' => $repositoryUrl), $io, $config);
} else {
throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
}
$parser = new VersionParser();
$candidates = array();
$requirements = $parser->parseNameVersionPairs(array($packageName));
$name = strtolower($requirements[0]['name']);
if (!$packageVersion && isset($requirements[0]['version'])) {
$packageVersion = $requirements[0]['version'];
}
$pool = new Pool($packageVersion ? 'dev' : $stability);
$pool->addRepository($sourceRepo);
$constraint = $packageVersion ? new VersionConstraint('=', $parser->normalize($packageVersion)) : null;
$candidates = $pool->whatProvides($name, $constraint);
foreach ($candidates as $key => $candidate) {
if ($candidate->getName() !== $name) {
unset($candidates[$key]);
}
}
if (!$candidates) {
throw new \InvalidArgumentException("Could not find package {$name}" . ($packageVersion ? " with version {$packageVersion}." : " with stability {$stability}."));
}
if (null === $directory) {
$parts = explode("/", $name, 2);
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
}
// select highest version if we have many
$package = $candidates[0];
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
unset($candidates);
$io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>');
if ($disableCustomInstallers) {
$io->write('<info>Custom installers have been disabled.</info>');
}
if (0 === strpos($package->getPrettyVersion(), 'dev-') && in_array($package->getSourceType(), array('git', 'hg'))) {
$package->setSourceReference(substr($package->getPrettyVersion(), 4));
}
$dm = $this->createDownloadManager($io, $config);
$dm->setPreferSource($preferSource)->setPreferDist($preferDist);
$projectInstaller = new ProjectInstaller($directory, $dm);
$im = $this->createInstallationManager();
$im->addInstaller($projectInstaller);
$im->install(new InstalledFilesystemRepository(new JsonFile('php://memory')), new InstallOperation($package));
$im->notifyInstalls();
$installedFromVcs = 'source' === $package->getInstallationSource();
$io->write('<info>Created project in ' . $directory . '</info>');
chdir($directory);
putenv('COMPOSER_ROOT_VERSION=' . $package->getPrettyVersion());
// clean up memory
unset($dm, $im, $config, $projectInstaller, $sourceRepo, $package);
// install dependencies of the created project
$composer = Factory::create($io);
$installer = Installer::create($io, $composer);
$installer->setPreferSource($preferSource)->setPreferDist($preferDist)->setDevMode($installDevPackages)->setRunScripts(!$noScripts);
if ($disableCustomInstallers) {
$installer->disableCustomInstallers();
}
if (!$installer->run()) {
return 1;
}
if (!$keepVcs && $installedFromVcs && (!$io->isInteractive() || $io->askConfirmation('<info>Do you want to remove the existing VCS (.git, .svn..) history?</info> [<comment>Y,n</comment>]? ', true))) {
$finder = new Finder();
$finder->depth(0)->directories()->in(getcwd())->ignoreVCS(false)->ignoreDotFiles(false);
foreach (array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg') as $vcsName) {
$finder->name($vcsName);
}
try {
$fs = new Filesystem();
$dirs = iterator_to_array($finder);
unset($finder);
foreach ($dirs as $dir) {
if (!$fs->removeDirectory($dir)) {
throw new \RuntimeException('Could not remove ' . $dir);
}
}
} catch (\Exception $e) {
$io->write('<error>An error occurred while removing the VCS metadata: ' . $e->getMessage() . '</error>');
}
}
return 0;
//.........这里部分代码省略.........