NavigationItem: Cast a string to Url already in setUrl()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-02 15:35:08 +02:00
parent 1788cc9b6a
commit 298c4ad38b

View File

@ -76,18 +76,18 @@ class NavigationItem implements Countable, IteratorAggregate
protected $parent; protected $parent;
/** /**
* URL * This item's url
* *
* @var Url|null * @var Url
*/ */
protected $url; protected $url;
/** /**
* URL parameters * Additional parameters for this item's url
* *
* @var array * @var array
*/ */
protected $urlParameters = array(); protected $urlParameters;
/** /**
* View * 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() public function getUrl()
{ {
if ($this->url !== null && ! $this->url instanceof Url) {
$this->url = Url::fromPath((string) $this->url);
}
return $this->url; return $this->url;
} }
/** /**
* Set the URL * Set this item's url
* *
* @param Url|string $url * @param Url|string $url
* *
* @return $this * @return $this
*
* @throws InvalidArgumentException If the given url is neither of type
*/ */
public function setUrl($url) 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; $this->url = $url;
return $this; return $this;
} }
/** /**
* Get the URL parameters * Return all additional parameters for this item's url
* *
* @return array * @return array
*/ */
public function getUrlParameters() 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 * @param array $urlParameters
* *