From 9647293f1b687d70703de88584fcf5fae895fab7 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 18 Dec 2014 17:11:30 +0100 Subject: [PATCH] Add our own dispatcher prototype for namespaced controllers refs #5786 --- library/Icinga/Web/Controller/Dispatcher.php | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 library/Icinga/Web/Controller/Dispatcher.php diff --git a/library/Icinga/Web/Controller/Dispatcher.php b/library/Icinga/Web/Controller/Dispatcher.php new file mode 100644 index 000000000..51e492ab5 --- /dev/null +++ b/library/Icinga/Web/Controller/Dispatcher.php @@ -0,0 +1,62 @@ +setResponse($response); + $controllerName = $request->getControllerName(); + if (! $controllerName) { + throw new LogicException('Controller name not found'); + } + $controllerName = ucfirst($controllerName) . 'Controller'; + if ($this->_defaultModule === $this->_curModule) { + $controllerClass = 'Icinga\\Controllers\\' . $controllerName; + } else { + $controllerClass = 'Icinga\\Module\\' . $this->_curModule . '\\Controllers\\' . $controllerName; + } + if (! class_exists($controllerClass)) { + return parent::dispatch($request, $response); + } + $controller = new $controllerClass($request, $response, $this->getParams()); + $actionName = $request->getActionName(); + if (! $actionName) { + throw new LogicException('Action name not found'); + } + $actionName = $actionName . 'Action'; + $request->setDispatched(true); + // Buffer output by default + $disableOb = $this->getParam('disableOutputBuffering'); + $obLevel = ob_get_level(); + if (empty($disableOb)) { + ob_start(); + } + try { + $controller->dispatch($actionName); + } catch (Exception $e) { + // Clean output buffer on error + $curObLevel = ob_get_level(); + if ($curObLevel > $obLevel) { + do { + ob_get_clean(); + $curObLevel = ob_get_level(); + } while ($curObLevel > $obLevel); + } + throw $e; + } + if (empty($disableOb)) { + $content = ob_get_clean(); + $response->appendBody($content); + } + } +}