From 298c4ad38b80273fa3f6202a96a8b1c9ae9b5b58 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 2 Sep 2015 15:35:08 +0200 Subject: [PATCH] NavigationItem: Cast a string to Url already in setUrl() refs #5600 --- .../Icinga/Web/Navigation/NavigationItem.php | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/library/Icinga/Web/Navigation/NavigationItem.php b/library/Icinga/Web/Navigation/NavigationItem.php index 5e168677c..b67f16e94 100644 --- a/library/Icinga/Web/Navigation/NavigationItem.php +++ b/library/Icinga/Web/Navigation/NavigationItem.php @@ -76,18 +76,18 @@ class NavigationItem implements Countable, IteratorAggregate protected $parent; /** - * URL + * This item's url * - * @var Url|null + * @var Url */ protected $url; /** - * URL parameters + * Additional parameters for this item's url * * @var array */ - protected $urlParameters = array(); + protected $urlParameters; /** * View @@ -373,43 +373,48 @@ class NavigationItem implements Countable, IteratorAggregate } /** - * Get the URL + * Return this item's url * - * @return Url|null + * @return Url */ public function getUrl() { - if ($this->url !== null && ! $this->url instanceof Url) { - $this->url = Url::fromPath((string) $this->url); - } return $this->url; } /** - * Set the URL + * Set this item's url * - * @param Url|string $url + * @param Url|string $url * * @return $this + * + * @throws InvalidArgumentException If the given url is neither of type */ public function setUrl($url) { + if (is_string($url)) { + $url = Url::fromPath($url); + } elseif (! $url instanceof Url) { + throw new InvalidArgumentException('Argument $url must be of type string or Url'); + } + $this->url = $url; return $this; } /** - * Get the URL parameters + * Return all additional parameters for this item's url * - * @return array + * @return array */ public function getUrlParameters() { - return $this->urlParameters; + return $this->urlParameters ?: array(); } /** - * Set the URL parameters + * Set additional parameters for this item's url * * @param array $urlParameters *