Merge branch 'bugfix/hook-view-6929'

fixes #6929
This commit is contained in:
Marius Hein 2014-08-27 11:32:10 +02:00
commit 24983c344c
5 changed files with 67 additions and 9 deletions

View File

@ -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;

View File

@ -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',

View File

@ -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);
}

View File

@ -0,0 +1,51 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Web\Hook;
use Zend_Controller_Action_HelperBroker;
use Zend_View;
/**
* Base class for web hooks
*
* The class provides access to the view
*/
class WebBaseHook
{
/**
* View instance
*
* @var Zend_View
*/
private $view;
/**
* Set the view instance
*
* @param Zend_View $view
*/
public function setView(Zend_View $view)
{
$this->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;
}
}

View File

@ -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(