From 4891afd64614b997108e9fa39255783cbabf51c5 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 17 Nov 2016 10:14:45 +0100 Subject: [PATCH] Add paramater type to ResourceFactory::getResourceConfigs() This allows to filter resources by type. --- library/Icinga/Data/ResourceFactory.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Data/ResourceFactory.php b/library/Icinga/Data/ResourceFactory.php index cf424963e..2721a8e46 100644 --- a/library/Icinga/Data/ResourceFactory.php +++ b/library/Icinga/Data/ResourceFactory.php @@ -56,14 +56,25 @@ class ResourceFactory implements ConfigAwareFactory } /** - * Return the configuration of all existing resources, or get all resources of a given type. + * Get the configuration of all existing resources, or all resources of the given type * - * @return Config The configuration containing all resources + * @param string $type Filter for resource type + * + * @return Config The resources configuration */ - public static function getResourceConfigs() + public static function getResourceConfigs($type = null) { self::assertResourcesExist(); - return self::$resources; + if ($type === null) { + return self::$resources; + } + $resources = array(); + foreach (self::$resources as $name => $resource) { + if ($resource->get('type') === $type) { + $resources[$name] = $resource; + } + } + return Config::fromArray($resources); } /**