Libraries: Add method `get($name)`

This commit is contained in:
Johannes Meyer 2020-11-13 17:43:17 +01:00
parent 01a08d60e1
commit 40c97d6a3e
1 changed files with 19 additions and 10 deletions

View File

@ -49,15 +49,8 @@ class Libraries implements IteratorAggregate
*/
public function has($name, $version = null)
{
$libVersion = null;
foreach ($this->libraries as $library) {
if ($library->getName() === $name) {
$libVersion = $library->getVersion();
break;
}
}
if ($libVersion === null) {
$library = $this->get($name);
if ($library === null) {
return false;
} elseif ($version === null) {
return true;
@ -69,6 +62,22 @@ class Libraries implements IteratorAggregate
$version = $match[2];
}
return version_compare($libVersion, $version, $operator);
return version_compare($library->getVersion(), $version, $operator);
}
/**
* Get a library by name
*
* @param string $name
*
* @return Library|null
*/
public function get($name)
{
foreach ($this->libraries as $library) {
if ($library->getName() === $name) {
return $library;
}
}
}
}