Dashboard: Defer construction of the Url object to Dashlet::getUrl()

Before, the Url object was constructed in Dashlet::setUrl() and Dashlet::__construct8) which lead to an exception when parsing a module's configuration.php from our CLI.

refs #9375
This commit is contained in:
Eric Lippmann 2015-08-10 14:05:08 +02:00
parent 1363ea4370
commit aa4e3c5a22
1 changed files with 11 additions and 15 deletions

View File

@ -20,7 +20,7 @@ class Dashlet extends UserWidget
/** /**
* The url of this Dashlet * The url of this Dashlet
* *
* @var \Icinga\Web\Url * @var Url|null
*/ */
private $url; private $url;
@ -74,16 +74,13 @@ EOD;
{ {
$this->title = $title; $this->title = $title;
$this->pane = $pane; $this->pane = $pane;
if ($url instanceof Url) { if (! $url) {
$this->url = $url;
} elseif ($url) {
$this->url = Url::fromPath($url);
} else {
throw new IcingaException( throw new IcingaException(
'Cannot create dashboard dashlet "%s" without valid URL', 'Cannot create dashboard dashlet "%s" without valid URL',
$title $title
); );
} }
$this->url = $url;
} }
/** /**
@ -107,10 +104,13 @@ EOD;
/** /**
* Retrieve the dashlets url * Retrieve the dashlets url
* *
* @return Url * @return Url|null
*/ */
public function getUrl() public function getUrl()
{ {
if ($this->url !== null && ! $this->url instanceof Url) {
$this->url = Url::fromPath($this->url);
}
return $this->url; return $this->url;
} }
@ -123,11 +123,7 @@ EOD;
*/ */
public function setUrl($url) public function setUrl($url)
{ {
if ($url instanceof Url) {
$this->url = $url; $this->url = $url;
} else {
$this->url = Url::fromPath($url);
}
return $this; return $this;
} }
@ -159,7 +155,7 @@ EOD;
public function toArray() public function toArray()
{ {
$array = array( $array = array(
'url' => $this->url->getRelativeUrl(), 'url' => $this->getUrl()->getRelativeUrl(),
'title' => $this->getTitle() 'title' => $this->getTitle()
); );
if ($this->getDisabled() === true) { if ($this->getDisabled() === true) {
@ -178,9 +174,9 @@ EOD;
} }
$view = $this->view(); $view = $this->view();
$url = clone($this->url); $url = $this->getUrl();
$url->setParam('view', 'compact'); $url->setParam('view', 'compact');
$iframeUrl = clone($url); $iframeUrl = clone $url;
$iframeUrl->setParam('isIframe'); $iframeUrl->setParam('isIframe');
$searchTokens = array( $searchTokens = array(