Libraries: Return partial matches in method `get()`

This allows to reference libraries with only their
project name, not just together with the organisation
name.
This commit is contained in:
Johannes Meyer 2020-11-18 16:52:22 +01:00
parent e8fc6f93ae
commit 79478fd2e1
1 changed files with 8 additions and 1 deletions

View File

@ -74,10 +74,17 @@ class Libraries implements IteratorAggregate
*/
public function get($name)
{
$candidate = null;
foreach ($this->libraries as $library) {
if ($library->getName() === $name) {
$libraryName = $library->getName();
if ($libraryName === $name) {
return $library;
} elseif (explode('/', $libraryName)[1] === $name) {
// Also return libs which only partially match
$candidate = $library;
}
}
return $candidate;
}
}