From 79478fd2e1f3793828390b58ea923d6945458392 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 18 Nov 2020 16:52:22 +0100 Subject: [PATCH] Libraries: Return partial matches in method `get()` This allows to reference libraries with only their project name, not just together with the organisation name. --- library/Icinga/Application/Libraries.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Libraries.php b/library/Icinga/Application/Libraries.php index 983381d2f..a911a3d38 100644 --- a/library/Icinga/Application/Libraries.php +++ b/library/Icinga/Application/Libraries.php @@ -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; } }