Web/controllers: use own Request/Response objects

* introduces Icinga\Web\Response
* uses ModuleActionController where necessary
* no module translationDomain voodoo in base ActionController
This commit is contained in:
Thomas Gelf 2014-06-22 13:49:21 +02:00
parent ef5e1b54fd
commit b7fc0b67a8
6 changed files with 46 additions and 23 deletions

View File

@ -37,6 +37,7 @@ use Icinga\Exception\ConfigurationError;
use Icinga\Exception\NotReadableError;
use Icinga\Logger\Logger;
use Icinga\Web\Request;
use Icinga\Web\Response;
use Icinga\Web\View;
use Icinga\Web\Session\Session as BaseSession;
use Icinga\Web\Session;
@ -48,7 +49,7 @@ use Exception;
use Zend_Layout;
use Zend_Paginator;
use Zend_View_Helper_PaginationControl;
use Zend_Controller_Action_HelperBroker;
use Zend_Controller_Action_HelperBroker as ActionHelperBroker;
use Zend_Controller_Router_Route;
use Zend_Controller_Front;
@ -124,7 +125,7 @@ class Web extends ApplicationBootstrap
->setupInternationalization()
->setupRequest()
->setupZendMvc()
->setupFormNamespace()
->setupFormNamespace()
->setupModuleManager()
->loadEnabledModules()
->setupRoute()
@ -177,7 +178,7 @@ class Web extends ApplicationBootstrap
*/
public function dispatch()
{
$this->frontController->dispatch();
$this->frontController->dispatch(new Request(), new Response());
}
/**
@ -274,7 +275,7 @@ class Web extends ApplicationBootstrap
private function setupViewRenderer()
{
/** @var \Zend_Controller_Action_Helper_ViewRenderer $view */
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view = ActionHelperBroker::getStaticHelper('viewRenderer');
$view->setView(new View());
$view->view->addHelperPath($this->getApplicationDir('/views/helpers'));

View File

@ -31,10 +31,6 @@
namespace Icinga\Web\Controller;
use Exception;
use Zend_Controller_Action;
use Zend_Controller_Request_Abstract;
use Zend_Controller_Response_Abstract;
use Zend_Controller_Action_HelperBroker;
use Icinga\Authentication\Manager as AuthManager;
use Icinga\Application\Benchmark;
use Icinga\Application\Config;
@ -49,6 +45,10 @@ use Icinga\Web\Session;
use Icinga\Web\UrlParams;
use Icinga\Session\SessionNamespace;
use Icinga\Exception\NotReadableError;
use Zend_Controller_Action;
use Zend_Controller_Action_HelperBroker as ActionHelperBroker;
use Zend_Controller_Request_Abstract as Request;
use Zend_Controller_Response_Abstract as Response;
/**
* Base class for all core action controllers
@ -93,13 +93,13 @@ class ActionController extends Zend_Controller_Action
* The constructor starts benchmarking, loads the configuration and sets
* other useful controller properties
*
* @param Zend_Controller_Request_Abstract $request
* @param Zend_Controller_Response_Abstract $response
* @param array $invokeArgs Any additional invocation arguments
* @param Request $request
* @param Response $response
* @param array $invokeArgs Any additional invocation arguments
*/
public function __construct(
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response,
Request $request,
Response $response,
array $invokeArgs = array()
) {
$this->params = UrlParams::fromQueryString();
@ -107,12 +107,10 @@ class ActionController extends Zend_Controller_Action
$this->setRequest($request)
->setResponse($response)
->_setInvokeArgs($invokeArgs);
$this->_helper = new Zend_Controller_Action_HelperBroker($this);
$this->_helper->addPath('../application/controllers/helpers');
$this->handlerBrowserWindows();
$this->_helper = new ActionHelperBroker($this);
$module = $request->getModuleName();
$this->view->translationDomain = $module === 'default' ? 'icinga' : $module;
$this->handlerBrowserWindows();
$this->view->translationDomain = 'icinga';
if ($this->requiresConfig() === false) {
if ($this->requiresLogin() === false) {

View File

@ -2,12 +2,27 @@
namespace Icinga\Web\Controller;
use Zend_Controller_Request_Abstract as Request;
use Zend_Controller_Response_Abstract as Response;
class ModuleActionController extends ActionController
{
private $config;
private $configs = array();
protected $moduleName;
public function __construct(
Request $request,
Response $response,
array $invokeArgs = array()
) {
parent::__construct($request, $response, $invokeArgs);
$this->moduleName = $request->getModuleName();
$this->view->translationDomain = $this->moduleName;
}
public function Config($file = null)
{
$module = $this->getRequest()->getModuleName();

View File

@ -0,0 +1,9 @@
<?php
namespace Icinga\Web;
use Zend_Controller_Response_Http;
class Response extends Zend_Controller_Response_Http
{
}

View File

@ -4,9 +4,9 @@
namespace Icinga\Module\Doc;
use Icinga\Web\Controller\ActionController;
use Icinga\Web\Controller\ModuleActionController;
class Controller extends ActionController
class Controller extends ModuleActionController
{
/**
* Set HTML and toc
@ -20,4 +20,4 @@ class Controller extends ActionController
$this->view->html = $html;
$this->view->toc = $toc;
}
}
}

View File

@ -29,14 +29,14 @@
namespace Icinga\Module\Monitoring;
use Icinga\Web\Controller\ActionController;
use Icinga\Web\Controller\ModuleActionController;
use Icinga\Web\Url;
use Icinga\File\Csv;
/**
* Base class for all monitoring action controller
*/
class Controller extends ActionController
class Controller extends ModuleActionController
{
/**
* The backend used for this controller