From aa4e3c5a22100ed76e0bb537a1c49730110a76be Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 10 Aug 2015 14:05:08 +0200 Subject: [PATCH] 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 --- .../Icinga/Web/Widget/Dashboard/Dashlet.php | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/library/Icinga/Web/Widget/Dashboard/Dashlet.php b/library/Icinga/Web/Widget/Dashboard/Dashlet.php index d972cc5d6..06d6851e2 100644 --- a/library/Icinga/Web/Widget/Dashboard/Dashlet.php +++ b/library/Icinga/Web/Widget/Dashboard/Dashlet.php @@ -20,7 +20,7 @@ class Dashlet extends UserWidget /** * The url of this Dashlet * - * @var \Icinga\Web\Url + * @var Url|null */ private $url; @@ -74,16 +74,13 @@ EOD; { $this->title = $title; $this->pane = $pane; - if ($url instanceof Url) { - $this->url = $url; - } elseif ($url) { - $this->url = Url::fromPath($url); - } else { + if (! $url) { throw new IcingaException( 'Cannot create dashboard dashlet "%s" without valid URL', $title ); } + $this->url = $url; } /** @@ -107,10 +104,13 @@ EOD; /** * Retrieve the dashlets url * - * @return Url + * @return Url|null */ public function getUrl() { + if ($this->url !== null && ! $this->url instanceof Url) { + $this->url = Url::fromPath($this->url); + } return $this->url; } @@ -123,11 +123,7 @@ EOD; */ public function setUrl($url) { - if ($url instanceof Url) { - $this->url = $url; - } else { - $this->url = Url::fromPath($url); - } + $this->url = $url; return $this; } @@ -159,7 +155,7 @@ EOD; public function toArray() { $array = array( - 'url' => $this->url->getRelativeUrl(), + 'url' => $this->getUrl()->getRelativeUrl(), 'title' => $this->getTitle() ); if ($this->getDisabled() === true) { @@ -178,9 +174,9 @@ EOD; } $view = $this->view(); - $url = clone($this->url); + $url = $this->getUrl(); $url->setParam('view', 'compact'); - $iframeUrl = clone($url); + $iframeUrl = clone $url; $iframeUrl->setParam('isIframe'); $searchTokens = array(