From 376e9aa16056e5e19f8a144963f0236ecfeb7f60 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Tue, 26 Aug 2014 14:29:55 +0200 Subject: [PATCH 1/2] Rename hook base classes Adding suffix "Hook" to every base class. This simplifies development because you don't need to alias bases classes in your concrete hook classes refs #6928 --- library/Icinga/Web/Hook/{Grapher.php => GrapherHook.php} | 2 +- library/Icinga/Web/Hook/{Ticket.php => TicketHook.php} | 2 +- library/Icinga/Web/Hook/{TopBar.php => TopBarHook.php} | 4 ++-- .../Hook/{TimelineProvider.php => TimelineProviderHook.php} | 2 +- modules/monitoring/library/Monitoring/Web/Hook/TopBar.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) rename library/Icinga/Web/Hook/{Grapher.php => GrapherHook.php} (99%) rename library/Icinga/Web/Hook/{Ticket.php => TicketHook.php} (97%) rename library/Icinga/Web/Hook/{TopBar.php => TopBarHook.php} (81%) rename modules/monitoring/library/Monitoring/Web/Hook/{TimelineProvider.php => TimelineProviderHook.php} (96%) diff --git a/library/Icinga/Web/Hook/Grapher.php b/library/Icinga/Web/Hook/GrapherHook.php similarity index 99% rename from library/Icinga/Web/Hook/Grapher.php rename to library/Icinga/Web/Hook/GrapherHook.php index 28de49604..e2fea304a 100644 --- a/library/Icinga/Web/Hook/Grapher.php +++ b/library/Icinga/Web/Hook/GrapherHook.php @@ -14,7 +14,7 @@ namespace Icinga\Web\Hook; * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ -class Grapher +class GrapherHook { /** * Whether this grapher provides preview images diff --git a/library/Icinga/Web/Hook/Ticket.php b/library/Icinga/Web/Hook/TicketHook.php similarity index 97% rename from library/Icinga/Web/Hook/Ticket.php rename to library/Icinga/Web/Hook/TicketHook.php index f9c1b495e..bb9a129b4 100644 --- a/library/Icinga/Web/Hook/Ticket.php +++ b/library/Icinga/Web/Hook/TicketHook.php @@ -14,7 +14,7 @@ namespace Icinga\Web\Hook; * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ -abstract class Ticket +abstract class TicketHook { /** * Constructor must live without arguments right now diff --git a/library/Icinga/Web/Hook/TopBar.php b/library/Icinga/Web/Hook/TopBarHook.php similarity index 81% rename from library/Icinga/Web/Hook/TopBar.php rename to library/Icinga/Web/Hook/TopBarHook.php index d32f6d1fd..695d81109 100644 --- a/library/Icinga/Web/Hook/TopBar.php +++ b/library/Icinga/Web/Hook/TopBarHook.php @@ -10,7 +10,7 @@ use \Zend_View; /** * Hook to extend topbar items */ -interface TopBar +abstract class TopBarHook { /** * Function to generate top bar content @@ -20,5 +20,5 @@ interface TopBar * * @return string */ - public function getHtml($request, $view); + abstract public function getHtml($request, $view); } diff --git a/modules/monitoring/library/Monitoring/Web/Hook/TimelineProvider.php b/modules/monitoring/library/Monitoring/Web/Hook/TimelineProviderHook.php similarity index 96% rename from modules/monitoring/library/Monitoring/Web/Hook/TimelineProvider.php rename to modules/monitoring/library/Monitoring/Web/Hook/TimelineProviderHook.php index cafe68c17..e265086ab 100644 --- a/modules/monitoring/library/Monitoring/Web/Hook/TimelineProvider.php +++ b/modules/monitoring/library/Monitoring/Web/Hook/TimelineProviderHook.php @@ -9,7 +9,7 @@ use Icinga\Module\Monitoring\Timeline\TimeRange; /** * Base class for TimeLine providers */ -abstract class TimelineProvider +abstract class TimelineProviderHook { /** * Return the names by which to group entries diff --git a/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php b/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php index 32efaca9a..9433bf805 100644 --- a/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php +++ b/modules/monitoring/library/Monitoring/Web/Hook/TopBar.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Monitoring\Web\Hook; -use Icinga\Web\Hook\TopBar as IcingaTopBar; +use Icinga\Web\Hook\TopBarHook; use Icinga\Module\Monitoring\DataView\StatusSummary as StatusSummaryView; use Icinga\Web\Request; use Zend_View; @@ -12,7 +12,7 @@ use Zend_View; /** * Render status summary into the topbar of icinga */ -class TopBar implements IcingaTopBar +class TopBar extends TopBarHook { /** * Function to generate top bar content From 7e5b5a0b30856c7904a18563e39e57c90efaa02f Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 09:35:43 +0200 Subject: [PATCH 2/2] Hook/Grapher: Rework hook interface Rework interface based on specification and changed consumer calls. refs #6932 --- library/Icinga/Web/Hook/GrapherHook.php | 63 +++++++++++++++---- .../controllers/ShowController.php | 11 ++-- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/library/Icinga/Web/Hook/GrapherHook.php b/library/Icinga/Web/Hook/GrapherHook.php index e2fea304a..99ab8a8f6 100644 --- a/library/Icinga/Web/Hook/GrapherHook.php +++ b/library/Icinga/Web/Hook/GrapherHook.php @@ -4,6 +4,8 @@ namespace Icinga\Web\Hook; +use Icinga\Exception\ProgrammingError; + /** * Icinga Web Grapher Hook base class * @@ -14,7 +16,7 @@ namespace Icinga\Web\Hook; * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ -class GrapherHook +abstract class GrapherHook { /** * Whether this grapher provides preview images @@ -56,9 +58,13 @@ class GrapherHook /** * Whether a graph for the given host[, service [, plot]] exists * + * @param string $host + * @param string $service + * @param string $plot + * * @return bool */ - public function hasGraph($host, $service = null, $plot = null) + public function has($host, $service = null, $plot = null) { return false; } @@ -66,13 +72,47 @@ class GrapherHook /** * Get a preview image for the given host[, service [, plot]] exists * - * WARNING: We are not sure yet whether this will remain as is + * @param string $host + * @param string $service + * @param string $plot * - * @return string + * @return string + * + * @throws ProgrammingError */ - public function getPreviewImage($host, $service = null, $plot = null) + public function getPreviewHtml($host, $service = null, $plot = null) { - throw new Exception('This backend has no preview images'); + throw new ProgrammingError('This backend has no preview images'); + } + + /** + * Whether a tiny graph for the given host[, service [, plot]] exists + * + * @param string $host + * @param string $service + * @param string $plot + * + * @return bool + */ + public function hasTinyPreview($host, $service = null, $plot = null) + { + return false; + } + + /** + * Get a tiny preview image for the given host[, service [, plot]] exists + * + * @param string $host + * @param string $service + * @param string $plot + * + * @return string + * + * @throws ProgrammingError + */ + public function getTinyPreviewHtml($host, $service = null, $plot = null) + { + throw new ProgrammingError('This backend has no tiny preview images'); } /** @@ -80,10 +120,11 @@ class GrapherHook * * WARNING: We are not sure yet whether this will remain as is * - * @return string + * @param string $host + * @param string $service + * @param string $plot + * + * @return string */ - public function getGraphUrl($host, $service = null, $plot = null) - { - throw new Exception('This backend has no images'); - } + abstract function getGraphUrl($host, $service = null, $plot = null); } diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index d503ba512..55b57cd52 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -25,6 +25,9 @@ class Monitoring_ShowController extends Controller */ protected $backend; + /** + * @var Hook\GrapherHook + */ protected $grapher; /** @@ -61,8 +64,8 @@ class Monitoring_ShowController extends Controller . ' on ' . $o->host_name; $this->getTabs()->activate('service'); $o->populate(); - if ($this->grapher && $this->grapher->hasGraph($o->host_name, $o->service_description)) { - $this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name, $o->service_description); + if ($this->grapher && $this->grapher->hasPreviews($o->host_name, $o->service_description)) { + $this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name, $o->service_description); } } @@ -76,8 +79,8 @@ class Monitoring_ShowController extends Controller $this->getTabs()->activate('host'); $this->view->title = $o->host_name; $o->populate(); - if ($this->grapher && $this->grapher->hasGraph($o->host_name)) { - $this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name); + if ($this->grapher && $this->grapher->hasPreviews($o->host_name)) { + $this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name); } }