1
0
Fork 0

Implement ComposerRepository::findPackage and ComposerRepository::findPackages.

pull/2988/head
Tristan Lins 2014-05-13 23:54:48 +02:00
parent 1efa02a7ab
commit a4d43ee860
1 changed files with 52 additions and 0 deletions

View File

@ -94,6 +94,58 @@ class ComposerRepository extends ArrayRepository implements StreamableRepository
$this->rootAliases = $rootAliases;
}
/**
* {@inheritDoc}
*/
public function findPackage($name, $version)
{
// normalize version & name
$versionParser = new VersionParser();
$version = $versionParser->normalize($version);
$name = strtolower($name);
foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) {
$packages = $this->whatProvides(new Pool('dev'), $providerName);
foreach ($packages as $package) {
if ($name == $package->getName() && $version === $package->getVersion()) {
return $package;
}
}
}
}
}
/**
* {@inheritDoc}
*/
public function findPackages($name, $version = null)
{
// normalize name
$name = strtolower($name);
// normalize version
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;
}
public function getPackages()
{
if ($this->hasProviders()) {