From e0d7c3855dec7fe92fedb253264299f6ff0be0c1 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 11:13:41 +0200 Subject: [PATCH 1/3] Hook: Add class suffix for base class testing refs #6928 --- library/Icinga/Web/Hook.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Hook.php b/library/Icinga/Web/Hook.php index 76200493a..b88069da1 100644 --- a/library/Icinga/Web/Hook.php +++ b/library/Icinga/Web/Hook.php @@ -41,6 +41,15 @@ class Hook */ public static $BASE_NS = 'Icinga\\Web\\Hook\\'; + /** + * Append this string to base class + * + * All base classes renamed to *Hook + * + * @var string + */ + public static $classSuffix = 'Hook'; + /** * Reset object state */ @@ -114,7 +123,7 @@ class Hook */ private static function assertValidHook($instance, $name) { - $base_class = self::$BASE_NS . ucfirst($name); + $base_class = self::$BASE_NS . ucfirst($name) . self::$classSuffix; if (!$instance instanceof $base_class) { throw new ProgrammingError( '%s is not an instance of %s', From b7ae66b496e750836cd619b898f5fb72475e7187 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 11:23:03 +0200 Subject: [PATCH 2/3] Hook: Add web hook base class refs #6929 --- library/Icinga/Web/Hook/WebBaseHook.php | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 library/Icinga/Web/Hook/WebBaseHook.php diff --git a/library/Icinga/Web/Hook/WebBaseHook.php b/library/Icinga/Web/Hook/WebBaseHook.php new file mode 100644 index 000000000..a901787bb --- /dev/null +++ b/library/Icinga/Web/Hook/WebBaseHook.php @@ -0,0 +1,51 @@ +view = $view; + } + + /** + * Get the view instance + * + * @return Zend_View + */ + public function getView() + { + if ($this->view === null) { + $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); + if ($viewRenderer->view === null) { + $viewRenderer->initView(); + } + $this->view = $viewRenderer->view; + } + + return $this->view; + } +} \ No newline at end of file From 88698cb05dfdc3f3c8d8d852bbf04e32209d3ffe Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 11:28:31 +0200 Subject: [PATCH 3/3] Hook/TopBar: Rework interface for monitoring top bar refs #6929 --- application/controllers/LayoutController.php | 4 ++-- library/Icinga/Web/Hook/TopBarHook.php | 5 ++--- modules/monitoring/library/Monitoring/Web/Hook/TopBar.php | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/application/controllers/LayoutController.php b/application/controllers/LayoutController.php index 952c4ee61..6c1355fc1 100644 --- a/application/controllers/LayoutController.php +++ b/application/controllers/LayoutController.php @@ -31,11 +31,11 @@ class LayoutController extends ActionController { $topbarHtmlParts = array(); - /** @var Hook\Layout\TopBar $hook */ + /** @var Hook\TopBarHook $hook */ $hook = null; foreach (Hook::all('TopBar') as $hook) { - $topbarHtmlParts[] = $hook->getHtml($this->getRequest(), $this->view); + $topbarHtmlParts[] = $hook->getHtml($this->getRequest()); } $this->view->topbarHtmlParts = $topbarHtmlParts; diff --git a/library/Icinga/Web/Hook/TopBarHook.php b/library/Icinga/Web/Hook/TopBarHook.php index fb637015d..183a0ca07 100644 --- a/library/Icinga/Web/Hook/TopBarHook.php +++ b/library/Icinga/Web/Hook/TopBarHook.php @@ -10,15 +10,14 @@ use Zend_View; /** * Hook to extend topbar items */ -abstract class TopBarHook +abstract class TopBarHook extends WebBaseHook { /** * Function to generate top bar content * * @param Request $request - * @param Zend_View $view * * @return string */ - abstract public function getHtml($request, $view); + abstract public function getHtml($request); } diff --git a/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php b/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php index 9433bf805..082a03c5b 100644 --- a/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php +++ b/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php @@ -18,11 +18,10 @@ class TopBar extends TopBarHook * Function to generate top bar content * * @param Request $request - * @param Zend_View $view * * @return string */ - public function getHtml($request, $view) + public function getHtml($request) { $hostSummary = StatusSummaryView::fromRequest( $request, @@ -50,7 +49,7 @@ class TopBar extends TopBarHook ) )->getQuery()->fetchRow(); - return $view->partial( + return $this->getView()->partial( 'layout/topbar.phtml', 'monitoring', array(