From b6fe6ffd6bf17b190102ec55dcfd10ea29471404 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 17 Sep 2015 13:41:28 +0200 Subject: [PATCH] Navigation: Relax type check in method fromConfig() refs #5600 --- library/Icinga/Web/Navigation/Navigation.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Web/Navigation/Navigation.php b/library/Icinga/Web/Navigation/Navigation.php index 0d22494af..6c1b931b9 100644 --- a/library/Icinga/Web/Navigation/Navigation.php +++ b/library/Icinga/Web/Navigation/Navigation.php @@ -9,7 +9,7 @@ use Exception; use Countable; use InvalidArgumentException; use IteratorAggregate; -use Icinga\Application\Config; +use Traversable; use Icinga\Application\Icinga; use Icinga\Application\Logger; use Icinga\Authentication\Auth; @@ -454,14 +454,22 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate /** * Create and return a new set of navigation items for the given configuration * - * @param Config $config + * Note that this is supposed to be utilized for one dimensional structures + * only. Multi dimensional structures can be processed by fromArray(). + * + * @param Traversable|array $config * * @return Navigation * - * @throws ConfigurationError In case a referenced parent does not exist + * @throws InvalidArgumentException In case the given configuration is invalid + * @throws ConfigurationError In case a referenced parent does not exist */ - public static function fromConfig(Config $config) + public static function fromConfig($config) { + if (! is_array($config) && !$config instanceof Traversable) { + throw new InvalidArgumentException('Argument $config must be an array or a instance of Traversable'); + } + $flattened = $topLevel = array(); foreach ($config as $sectionName => $sectionConfig) { $parentName = $sectionConfig->parent;