added findPackage() method to the RepositoryManager and RepositoryInterface
parent
21191ffa00
commit
cc2f2b79ca
|
@ -23,6 +23,23 @@ class ArrayRepository implements RepositoryInterface
|
||||||
{
|
{
|
||||||
protected $packages;
|
protected $packages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a package by it's name and version (if has one).
|
||||||
|
*
|
||||||
|
* @param string $name package name
|
||||||
|
* @param string $version package version
|
||||||
|
*
|
||||||
|
* @return PackageInterface|null
|
||||||
|
*/
|
||||||
|
public function findPackage($name, $version)
|
||||||
|
{
|
||||||
|
foreach ($this->getPackages() as $package) {
|
||||||
|
if ($name === $package->getName() && $version === $package->getVersion()) {
|
||||||
|
return $package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if specified package in this repository.
|
* Checks if specified package in this repository.
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,6 +31,16 @@ interface RepositoryInterface extends \Countable
|
||||||
*/
|
*/
|
||||||
function hasPackage(PackageInterface $package);
|
function hasPackage(PackageInterface $package);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a package by it's name and version (if has one).
|
||||||
|
*
|
||||||
|
* @param string $name package name
|
||||||
|
* @param string $version package version
|
||||||
|
*
|
||||||
|
* @return PackageInterface|null
|
||||||
|
*/
|
||||||
|
function findPackage($name, $version);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns list of registered packages.
|
* Returns list of registered packages.
|
||||||
*
|
*
|
||||||
|
|
|
@ -22,6 +22,23 @@ class RepositoryManager
|
||||||
private $localRepository;
|
private $localRepository;
|
||||||
private $repositories = array();
|
private $repositories = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a package by it's name and version in managed repositories.
|
||||||
|
*
|
||||||
|
* @param string $name package name
|
||||||
|
* @param string $version package version
|
||||||
|
*
|
||||||
|
* @return PackageInterface|null
|
||||||
|
*/
|
||||||
|
public function findPackage($name, $version)
|
||||||
|
{
|
||||||
|
foreach ($this->repositories as $repository) {
|
||||||
|
if ($package = $repository->findPackage($name, $version)) {
|
||||||
|
return $package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets repository with specific name.
|
* Sets repository with specific name.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue