本文整理汇总了PHP中Composer\DependencyResolver\Pool::addRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP Pool::addRepository方法的具体用法?PHP Pool::addRepository怎么用?PHP Pool::addRepository使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\DependencyResolver\Pool
的用法示例。
在下文中一共展示了Pool::addRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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());
}
示例3: 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);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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());
}
}
示例7: 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;
}
示例8: getPool
private function getPool(InputInterface $input)
{
if (!$this->pool) {
$this->pool = new Pool($this->getMinimumStability($input));
$this->pool->addRepository($this->getRepos());
}
return $this->pool;
}
示例9: 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;
}
示例10: 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);
}
}
}
示例11: 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);
}
示例12: 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;
}
示例13: 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());
}
示例14: 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);
}
}
}
示例15: getOperations
/**
* @return InstallOperation[]
*/
private function getOperations()
{
foreach ($this->aliases as $alias) {
// we need to replace the version of aliased packages in the local
// repository by their aliases in the root package (composer always
// stores the actual installed version instead), otherwise the whole
// dependency resolution below will fail.
$aliased = $this->localRepo->findPackage($alias['package'], $alias['version']);
$version = new \ReflectionProperty('Composer\\Package\\Package', 'version');
$version->setAccessible(true);
$version->setValue($aliased, $alias['alias_normalized']);
}
$toRepo = new ArrayRepository();
$pool = new Pool();
$pool->addRepository($this->localRepo);
$pool->addRepository(new PlatformRepository());
$request = new Request($pool);
foreach ($this->localRepo->getCanonicalPackages() as $package) {
$request->install($package->getName());
}
$solver = new Solver(new DefaultPolicy(), $pool, $toRepo, new NullIO());
return $solver->solve($request);
}