本文整理汇总了PHP中Composer\Repository\ArrayRepository::findPackages方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayRepository::findPackages方法的具体用法?PHP ArrayRepository::findPackages怎么用?PHP ArrayRepository::findPackages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Repository\ArrayRepository
的用法示例。
在下文中一共展示了ArrayRepository::findPackages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFindPackages
public function testFindPackages()
{
$repo = new ArrayRepository();
$repo->addPackage($this->getPackage('foo', '1'));
$repo->addPackage($this->getPackage('bar', '2'));
$repo->addPackage($this->getPackage('bar', '3'));
$foo = $repo->findPackages('foo');
$this->assertCount(1, $foo);
$this->assertEquals('foo', $foo[0]->getName());
$bar = $repo->findPackages('bar');
$this->assertCount(2, $bar);
$this->assertEquals('bar', $bar[0]->getName());
}
示例2: findPackages
/**
* {@inheritDoc}
*/
public function findPackages($name, $constraint = null)
{
if (!$this->hasProviders()) {
return parent::findPackages($name, $constraint);
}
// normalize name
$name = strtolower($name);
if (null !== $constraint && !$constraint instanceof ConstraintInterface) {
$versionParser = new VersionParser();
$constraint = $versionParser->parseConstraints($constraint);
}
$packages = array();
foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) {
$candidates = $this->whatProvides(new Pool('dev'), $providerName);
foreach ($candidates as $package) {
if ($name === $package->getName()) {
$pkgConstraint = new Constraint('==', $package->getVersion());
if (null === $constraint || $constraint->matches($pkgConstraint)) {
$packages[] = $package;
}
}
}
break;
}
}
return $packages;
}
示例3: findPackages
public function findPackages($name, $version = null)
{
if (!$this->hasProviders()) {
return parent::findPackages($name, $version);
}
$name = strtolower($name);
if (null !== $version) {
$versionParser = new VersionParser();
$version = $versionParser->normalize($version);
}
$packages = array();
foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) {
$packages = $this->whatProvides(new Pool('dev'), $providerName);
foreach ($packages as $package) {
if ($name == $package->getName() && (null === $version || $version === $package->getVersion())) {
$packages[] = $package;
}
}
}
}
return $packages;
}