From b7fc0b67a81b2d044bde873603b36f45353026ce Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 22 Jun 2014 13:49:21 +0200 Subject: [PATCH] Web/controllers: use own Request/Response objects * introduces Icinga\Web\Response * uses ModuleActionController where necessary * no module translationDomain voodoo in base ActionController --- library/Icinga/Application/Web.php | 9 ++++--- .../Web/Controller/ActionController.php | 26 +++++++++---------- .../Web/Controller/ModuleActionController.php | 15 +++++++++++ library/Icinga/Web/Response.php | 9 +++++++ modules/doc/library/Doc/Controller.php | 6 ++--- .../library/Monitoring/Controller.php | 4 +-- 6 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 library/Icinga/Web/Response.php diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index f0964e779..d12638887 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -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')); diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index e4c8b3f7f..f687ce237 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -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) { diff --git a/library/Icinga/Web/Controller/ModuleActionController.php b/library/Icinga/Web/Controller/ModuleActionController.php index d718cc19e..4f1a4c847 100644 --- a/library/Icinga/Web/Controller/ModuleActionController.php +++ b/library/Icinga/Web/Controller/ModuleActionController.php @@ -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(); diff --git a/library/Icinga/Web/Response.php b/library/Icinga/Web/Response.php new file mode 100644 index 000000000..6e2e84656 --- /dev/null +++ b/library/Icinga/Web/Response.php @@ -0,0 +1,9 @@ +view->html = $html; $this->view->toc = $toc; } -} \ No newline at end of file +} diff --git a/modules/monitoring/library/Monitoring/Controller.php b/modules/monitoring/library/Monitoring/Controller.php index ca5d6f514..fd1358c12 100644 --- a/modules/monitoring/library/Monitoring/Controller.php +++ b/modules/monitoring/library/Monitoring/Controller.php @@ -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