本文整理汇总了PHP中Composer\DependencyResolver\Pool类的典型用法代码示例。如果您正苦于以下问题:PHP Pool类的具体用法?PHP Pool怎么用?PHP Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: doExecute
/**
* Execute the command.
*
* @param InputInterface $input
* @param OutputInterface $output
* @param bool $inverted Whether to invert matching process (why-not vs why behaviour)
* @return int|null Exit code of the operation.
*/
protected function doExecute(InputInterface $input, OutputInterface $output, $inverted = false)
{
// Emit command event on startup
$composer = $this->getComposer();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, $this->getName(), $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
// Prepare repositories and set up a pool
$platformOverrides = $composer->getConfig()->get('platform') ?: array();
$repository = new CompositeRepository(array(new ArrayRepository(array($composer->getPackage())), $composer->getRepositoryManager()->getLocalRepository(), new PlatformRepository(array(), $platformOverrides)));
$pool = new Pool();
$pool->addRepository($repository);
// Parse package name and constraint
list($needle, $textConstraint) = array_pad(explode(':', $input->getArgument(self::ARGUMENT_PACKAGE)), 2, $input->getArgument(self::ARGUMENT_CONSTRAINT));
// Find packages that are or provide the requested package first
$packages = $pool->whatProvides($needle);
if (empty($packages)) {
throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle));
}
// If the version we ask for is not installed then we need to locate it in remote repos and add it.
// This is needed for why-not to resolve conflicts from an uninstalled version against installed packages.
if (!$repository->findPackage($needle, $textConstraint)) {
$defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos($this->getIO()));
if ($match = $defaultRepos->findPackage($needle, $textConstraint)) {
$repository->addRepository(new ArrayRepository(array(clone $match)));
}
}
// Include replaced packages for inverted lookups as they are then the actual starting point to consider
$needles = array($needle);
if ($inverted) {
foreach ($packages as $package) {
$needles = array_merge($needles, array_map(function (Link $link) {
return $link->getTarget();
}, $package->getReplaces()));
}
}
// Parse constraint if one was supplied
if ('*' !== $textConstraint) {
$versionParser = new VersionParser();
$constraint = $versionParser->parseConstraints($textConstraint);
} else {
$constraint = null;
}
// Parse rendering options
$renderTree = $input->getOption(self::OPTION_TREE);
$recursive = $renderTree || $input->getOption(self::OPTION_RECURSIVE);
// Resolve dependencies
$results = $repository->getDependents($needles, $constraint, $inverted, $recursive);
if (empty($results)) {
$extra = null !== $constraint ? sprintf(' in versions %smatching %s', $inverted ? 'not ' : '', $textConstraint) : '';
$this->getIO()->writeError(sprintf('<info>There is no installed package depending on "%s"%s</info>', $needle, $extra));
} elseif ($renderTree) {
$this->initStyles($output);
$root = $packages[0];
$this->getIO()->write(sprintf('<info>%s</info> %s %s', $root->getPrettyName(), $root->getPrettyVersion(), $root->getDescription()));
$this->printTree($results);
} else {
$this->printTable($output, $results);
}
return 0;
}
开发者ID:neon64,项目名称:composer,代码行数:68,代码来源:BaseDependencyCommand.php
示例2: has
/**
* Search for a given package version.
*
* Usage examples : Composition::has('php', '5.3.*') // PHP version
* Composition::has('ext-memcache') // PHP extension
* Composition::has('vendor/package', '>2.1') // Package version
*
* @param type $packageName The package name
* @param type $prettyString An optional version constraint
*
* @return boolean Wether or not the package has been found.
*/
public static function has($packageName, $prettyString = '*')
{
if (null === self::$pool) {
if (null === self::$rootDir) {
self::$rootDir = getcwd();
if (!file_exists(self::$rootDir . '/composer.json')) {
throw new \RuntimeException('Unable to guess the project root dir, please specify it manually using the Composition::setRootDir method.');
}
}
$minimumStability = 'dev';
$config = new Config();
$file = new JsonFile(self::$rootDir . '/composer.json');
if ($file->exists()) {
$projectConfig = $file->read();
$config->merge($projectConfig);
if (isset($projectConfig['minimum-stability'])) {
$minimumStability = $projectConfig['minimum-stability'];
}
}
$vendorDir = self::$rootDir . '/' . $config->get('vendor-dir');
$pool = new Pool($minimumStability);
$pool->addRepository(new PlatformRepository());
$pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
$pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed_dev.json')));
self::$pool = $pool;
}
$parser = new VersionParser();
$constraint = $parser->parseConstraints($prettyString);
$packages = self::$pool->whatProvides($packageName, $constraint);
return empty($packages) ? false : true;
}
开发者ID:bamarni,项目名称:composition,代码行数:43,代码来源:Composition.php
示例3: selectPackage
protected function selectPackage(IOInterface $io, $packageName, $version = null)
{
$io->write('<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->write('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);
$constraint = $version ? new VersionConstraint('>=', $version) : null;
$packages = $pool->whatProvides($packageName, $constraint);
if (count($packages) > 1) {
$package = $packages[0];
$io->write('<info>Found multiple matches, selected ' . $package->getPrettyString() . '.</info>');
$io->write('Alternatives were ' . implode(', ', array_map(function ($p) {
return $p->getPrettyString();
}, $packages)) . '.');
$io->write('<comment>Please use a more specific constraint to pick a different package.</comment>');
} elseif ($packages) {
$package = $packages[0];
$io->write('<info>Found an exact match ' . $package->getPrettyString() . '.</info>');
} else {
$io->write('<error>Could not find a package matching ' . $packageName . '.</error>');
return false;
}
return $package;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:31,代码来源:ArchiveCommand.php
示例4: testInjectCoreBundles
/**
* Test that the core bundles get correctly injected.
*
* @return void
*/
public function testInjectCoreBundles()
{
$inOut = $this->getMock('Composer\\IO\\IOInterface');
$factory = new Factory();
$composer = $factory->createComposer($inOut, $this->config);
$plugin = new Plugin();
$local = $composer->getRepositoryManager()->getLocalRepository();
if ($core = $local->findPackages('contao/core')) {
$this->fail('Contao core has already been injected, found version ' . $core[0]->getVersion());
}
$plugin->activate($composer, $inOut);
if (!($core = $local->findPackages('contao/core'))) {
$this->fail('Contao core has not been injected.');
}
$core = $core[0];
$constraint = new Constraint('=', $core->getVersion());
$pool = new Pool('dev');
$pool->addRepository($local);
$this->assertNotNull($core = $pool->whatProvides('contao/core', $constraint));
// bundle names + 'contao-community-alliance/composer-client'
$this->assertCount(8, $core[0]->getRequires());
foreach (array('contao/calendar-bundle', 'contao/comments-bundle', 'contao/core-bundle', 'contao/faq-bundle', 'contao/listing-bundle', 'contao/news-bundle', 'contao/newsletter-bundle') as $bundleName) {
$this->assertNotNull($matches = $pool->whatProvides($bundleName, $constraint));
$this->assertCount(1, $matches);
$this->assertEquals('metapackage', $matches[0]->getType());
}
}
开发者ID:Jobu,项目名称:core,代码行数:32,代码来源:InjectCoreBundlesTest.php
示例5: package
protected function package($matches)
{
$hash = $matches['hash'];
$name = $matches['name'];
$filename = 'p/hash/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/' . $hash . hash('md5', $hash . $name) . '.json';
if (!file_exists($filename)) {
$repos = $this->getRepos();
$pool = new Pool('dev');
foreach ($repos as $repo) {
try {
$pool->addRepository($repo);
} catch (\RuntimeException $e) {
}
}
$matches = $pool->whatProvides($name, null);
if (!$matches) {
return '{}';
} else {
$match = $matches[0];
$repo = $match->getRepository();
$ref = new \ReflectionProperty($repo, 'cache');
$ref->setAccessible(true);
$cache = $ref->getValue($repo);
$cacheKey = 'provider-' . strtr($name, '/', '$') . '.json';
$packages = $cache->read($cacheKey);
if (empty($packages)) {
throw new \Exception("Cache should exists, please report this issue on github", 1);
}
mkdir(dirname($filename), 0755, true);
file_put_contents($filename, $packages);
}
}
return file_get_contents($filename);
}
开发者ID:garveen,项目名称:imagist,代码行数:34,代码来源:Imagist.php
示例6: matchesCakeVersion
/**
* Check if CakePHP version matches against a version
*
* @param string $matcher
* @param string $version
* @return bool
*/
protected function matchesCakeVersion($matcher, $version)
{
if (class_exists('Composer\\Semver\\Constraint\\MultiConstraint')) {
$multiClass = 'Composer\\Semver\\Constraint\\MultiConstraint';
$constraintClass = 'Composer\\Semver\\Constraint\\Constraint';
} else {
$multiClass = 'Composer\\Package\\LinkConstraint\\MultiConstraint';
$constraintClass = 'Composer\\Package\\LinkConstraint\\VersionConstraint';
}
$repositoryManager = $this->composer->getRepositoryManager();
if ($repositoryManager) {
$repos = $repositoryManager->getLocalRepository();
if (!$repos) {
return false;
}
$cake3 = new $multiClass(array(new $constraintClass($matcher, $version), new $constraintClass('!=', '9999999-dev')));
$pool = new Pool('dev');
$pool->addRepository($repos);
$packages = $pool->whatProvides('cakephp/cakephp');
foreach ($packages as $package) {
$installed = new $constraintClass('=', $package->getVersion());
if ($cake3->matches($installed)) {
return true;
break;
}
}
}
return false;
}
开发者ID:billythekid,项目名称:prodder,代码行数:36,代码来源:CakePHPInstaller.php
示例7: getPackageMatches
private function getPackageMatches($repository, $name, $version = null)
{
$pool = new Pool('dev');
$pool->addRepository($repository);
$constraint = null;
if ($version) {
$parser = new VersionParser();
$constraint = $parser->parseConstraints($version);
}
return $pool->whatProvides($name, $constraint);
}
开发者ID:quickstrap,项目名称:quickstrap,代码行数:11,代码来源:PackageHelper.php
示例8: addRepositoryInstance
/**
* Add repository instance.
*
* @param IOInterface $io The IO instance
* @param RepositoryManager $rm The repository mamanger
* @param array $repos The list of already repository added (passed by reference)
* @param string $name The name of the new repository
* @param RepositoryInterface $repo The repository instance
* @param Pool|null $pool The pool
*/
public static function addRepositoryInstance(IOInterface $io, RepositoryManager $rm, array &$repos, $name, RepositoryInterface $repo, Pool $pool = null)
{
if (!isset($repos[$name])) {
static::writeAddRepository($io, $name);
$repos[$name] = $repo;
$rm->addRepository($repo);
if (null !== $pool) {
$pool->addRepository($repo);
}
}
}
开发者ID:MvegaR,项目名称:ingSotfware,代码行数:21,代码来源:Util.php
示例9: testGetMaxId
public function testGetMaxId()
{
$pool = new Pool();
$repository = new ArrayRepository();
$firstPackage = $this->getPackage('foo', '1');
$secondPackage = $this->getPackage('foo1', '1');
$this->assertEquals(0, $pool->getMaxId());
$repository->addPackage($firstPackage);
$repository->addPackage($secondPackage);
$pool->addRepository($repository);
$this->assertEquals(2, $pool->getMaxId());
}
开发者ID:natxet,项目名称:composer,代码行数:12,代码来源:PoolTest.php
示例10: addRepository
/**
* @param RepositoryManager $rm The repository mamanger
* @param array $repos The list of already repository added (passed by reference)
* @param string $name The name of the new repository
* @param array $repoConfig The config of the new repository
* @param Pool|null $pool The pool
*/
public static function addRepository(RepositoryManager $rm, array &$repos, $name, array $repoConfig, Pool $pool = null)
{
if (!isset($repos[$name])) {
$repo = $rm->createRepository($repoConfig['type'], $repoConfig);
$repos[$name] = $repo;
$rm->addRepository($repo);
if (null !== $pool) {
$pool->addRepository($repo);
}
}
}
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:19,代码来源:Util.php
示例11: testRequestInstallSamePackageFromDifferentRepositories
public function testRequestInstallSamePackageFromDifferentRepositories()
{
$pool = new Pool();
$repo1 = new ArrayRepository();
$repo2 = new ArrayRepository();
$foo1 = $this->getPackage('foo', '1');
$foo2 = $this->getPackage('foo', '1');
$repo1->addPackage($foo1);
$repo2->addPackage($foo2);
$pool->addRepository($repo1);
$pool->addRepository($repo2);
$request = new Request($pool);
$request->install('foo', $constraint = $this->getVersionConstraint('=', '1'));
$this->assertEquals(array(array('packages' => array($foo1, $foo2), 'cmd' => 'install', 'packageName' => 'foo', 'constraint' => $constraint)), $request->getJobs());
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:15,代码来源:RequestTest.php
示例12: getPackage
/**
* finds a package by name
*
* @param RepositoryInterface $repos
* @param string $name
* @return CompletePackageInterface
*/
protected function getPackage(RepositoryInterface $repos, $name)
{
$name = strtolower($name);
$pool = new Pool('dev');
$pool->addRepository($repos);
$matches = $pool->whatProvides($name);
foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
return $package;
}
}
开发者ID:composer-fork,项目名称:composer,代码行数:22,代码来源:HomeCommand.php
示例13: getRequiredPool
/**
* If the version we ask for is not installed then we need to locate it in
* remote repos and add it.
*
* This is needed for why-not to resolve conflicts from an uninstalled
* version against installed packages.
*
* @param string $packageName Package to inspect.
* @param string $textConstraint Optional version constraint
* @param bool $onlyLocal
*
* @return Pool
*/
private function getRequiredPool($packageName, $textConstraint, $onlyLocal)
{
if ($onlyLocal === false) {
return $this->getPool();
}
$composer = $this->getComposer();
$pool = new Pool();
// Prepare repositories and set up a pool
$platformOverrides = $composer->getConfig()->get('platform') ?: [];
/** @var BasePackage $rootPackage */
$rootPackage = $composer->getPackage();
if ($rootPackage->getRepository() === null) {
$packageRepo = new ArrayRepository([$composer->getPackage()]);
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$platformRepo = new PlatformRepository([], $platformOverrides);
$compositeRepository = new CompositeRepository([$packageRepo, $localRepo, $platformRepo]);
$pool->addRepository($compositeRepository);
$defaultRepos = new CompositeRepository(RepositoryFactory::defaultRepos($this->getIO()));
$match = $defaultRepos->findPackage($packageName, $textConstraint);
if ($match) {
$compositeRepository->addRepository(new ArrayRepository([clone $match]));
}
}
return $pool;
}
开发者ID:bolt,项目名称:bolt,代码行数:38,代码来源:AbstractDependencyAction.php
示例14: getPool
private function getPool(Composer $composer)
{
if (!$this->pool) {
$this->pool = new Pool($composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags());
$this->pool->addRepository(new CompositeRepository($composer->getRepositoryManager()->getRepositories()));
}
return $this->pool;
}
开发者ID:detain,项目名称:composer,代码行数:8,代码来源:ShowCommand.php
示例15: getPool
private function getPool(InputInterface $input)
{
if (!$this->pool) {
$this->pool = new Pool($this->getMinimumStability($input));
$this->pool->addRepository($this->getRepos());
}
return $this->pool;
}
开发者ID:alancleaver,项目名称:composer,代码行数:8,代码来源:InitCommand.php
示例16: testRequestInstallAndRemove
public function testRequestInstallAndRemove()
{
$pool = new Pool();
$repo = new ArrayRepository();
$foo = $this->getPackage('foo', '1');
$bar = $this->getPackage('bar', '1');
$foobar = $this->getPackage('foobar', '1');
$repo->addPackage($foo);
$repo->addPackage($bar);
$repo->addPackage($foobar);
$pool->addRepository($repo);
$request = new Request($pool);
$request->install('foo');
$request->install('bar');
$request->remove('foobar');
$this->assertEquals(array(array('packages' => array($foo), 'cmd' => 'install', 'packageName' => 'foo'), array('packages' => array($bar), 'cmd' => 'install', 'packageName' => 'bar'), array('packages' => array($foobar), 'cmd' => 'remove', 'packageName' => 'foobar')), $request->getJobs());
}
开发者ID:natxet,项目名称:composer,代码行数:17,代码来源:RequestTest.php
示例17: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'depends', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$repo = new CompositeRepository(array(new ArrayRepository(array($composer->getPackage())), $composer->getRepositoryManager()->getLocalRepository()));
$needle = $input->getArgument('package');
$pool = new Pool();
$pool->addRepository($repo);
$packages = $pool->whatProvides($needle);
if (empty($packages)) {
throw new \InvalidArgumentException('Could not find package "' . $needle . '" in your project.');
}
$linkTypes = $this->linkTypes;
$types = array_map(function ($type) use($linkTypes) {
$type = rtrim($type, 's');
if (!isset($linkTypes[$type])) {
throw new \InvalidArgumentException('Unexpected link type: ' . $type . ', valid types: ' . implode(', ', array_keys($linkTypes)));
}
return $type;
}, $input->getOption('link-type'));
$messages = array();
$outputPackages = array();
$io = $this->getIO();
/** @var PackageInterface $package */
foreach ($repo->getPackages() as $package) {
foreach ($types as $type) {
/** @var Link $link */
foreach ($package->{'get' . $linkTypes[$type][0]}() as $link) {
if ($link->getTarget() === $needle) {
if (!isset($outputPackages[$package->getName()])) {
$messages[] = '<info>' . $package->getPrettyName() . '</info> ' . $linkTypes[$type][1] . ' ' . $needle . ' (<info>' . $link->getPrettyConstraint() . '</info>)';
$outputPackages[$package->getName()] = true;
}
}
}
}
}
if ($messages) {
sort($messages);
$io->write($messages);
} else {
$io->writeError('<info>There is no installed package depending on "' . $needle . '".</info>');
}
}
开发者ID:hanovruslan,项目名称:composer,代码行数:45,代码来源:DependsCommand.php
示例18: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$repos = $this->getComposer()->getRepositoryManager()->getLocalRepositories();
$needle = $input->getArgument('package');
$pool = new Pool();
foreach ($repos as $repo) {
$pool->addRepository($repo);
}
$packages = $pool->whatProvides($needle);
if (empty($packages)) {
throw new \InvalidArgumentException('Could not find package "' . $needle . '" in your project.');
}
$linkTypes = $this->linkTypes;
$verbose = (bool) $input->getOption('verbose');
$types = array_map(function ($type) use($linkTypes) {
$type = rtrim($type, 's');
if (!isset($linkTypes[$type])) {
throw new \InvalidArgumentException('Unexpected link type: ' . $type . ', valid types: ' . implode(', ', array_keys($linkTypes)));
}
return $type;
}, $input->getOption('link-type'));
$dependsOnPackages = false;
foreach ($repos as $repo) {
$repo->filterPackages(function ($package) use($needle, $types, $linkTypes, $output, $verbose, &$dependsOnPackages) {
static $outputPackages = array();
foreach ($types as $type) {
foreach ($package->{'get' . $linkTypes[$type]}() as $link) {
if ($link->getTarget() === $needle) {
$dependsOnPackages = true;
if ($verbose) {
$output->writeln($package->getPrettyName() . ' ' . $package->getPrettyVersion() . ' <info>' . $type . '</info> ' . $link->getPrettyConstraint());
} elseif (!isset($outputPackages[$package->getName()])) {
$output->writeln($package->getPrettyName());
$outputPackages[$package->getName()] = true;
}
}
}
}
});
}
if (!$dependsOnPackages) {
$output->writeln('<info>There is no installed package depending on "' . $needle . '".</info>');
}
}
开发者ID:nickelc,项目名称:composer,代码行数:44,代码来源:DependsCommand.php
示例19: getInstalled
/**
* @return PackageInterface[]
*/
public function getInstalled()
{
$composer = Factory::create(new NullIO(), $this->config);
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$repos = new CompositeRepository(array_merge(array($localRepo), $composer->getRepositoryManager()->getRepositories()));
$pool = new Pool();
$pool->addRepository($repos);
$vs = new VersionSelector($pool);
$packages = [];
foreach ($localRepo->getPackages() as $package) {
if (!isset($packages[$package->getName()]) || !is_object($packages[$package->getName()]) || version_compare($packages[$package->getName()]->getVersion(), $package->getVersion(), '<')) {
if ($package instanceof CompletePackageInterface) {
$latestPackage = $vs->findBestCandidate($package->getName());
$package = new InstalledPackage($package, $latestPackage);
}
$packages[$package->getName()] = $package;
}
}
return $packages;
}
开发者ID:mathielen,项目名称:package-manager,代码行数:23,代码来源:ApplicationManager.php
示例20: getPool
/**
* Return a resolver pool that contains repositories, that provide packages.
*
* @return \Composer\DependencyResolver\Pool
*/
public function getPool()
{
if (!$this->pool) {
$this->pool = new Pool($this->getMinimumStability());
// Add each of our configured repos to the pool,
// or it defaults to packagist.org
foreach ($this->getRepos() as $repo) {
$this->pool->addRepository($repo);
}
}
return $this->pool;
}
开发者ID:aleksabp,项目名称:bolt,代码行数:17,代码来源:Factory.php
注:本文中的Composer\DependencyResolver\Pool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论