Add Module::addRoute() to add a route to the route chain

refs #6303
This commit is contained in:
Eric Lippmann 2014-05-26 13:33:32 +02:00
parent 5923622fb8
commit b58ec5f445

View File

@ -30,6 +30,7 @@
namespace Icinga\Application\Modules; namespace Icinga\Application\Modules;
use Exception; use Exception;
use Zend_Controller_Router_Route_Abstract;
use Zend_Controller_Router_Route as Route; use Zend_Controller_Router_Route as Route;
use Icinga\Application\ApplicationBootstrap; use Icinga\Application\ApplicationBootstrap;
use Icinga\Application\Config; use Icinga\Application\Config;
@ -150,6 +151,16 @@ class Module
*/ */
private $app; private $app;
/**
* Routes to add to the route chain
*
* @var array Array of name-route pairs
*
* @see addRoute()
*/
protected $routes = array();
/** /**
* Create a new module object * Create a new module object
* *
@ -594,13 +605,17 @@ class Module
} }
/** /**
* Register routes for web access * Add routes for static content and any route added via addRoute() to the route chain
* *
* @return self * @return self
* @see addRoute()
*/ */
protected function registerRoutes() protected function registerRoutes()
{ {
$router = $this->app->getFrontController()->getRouter(); $router = $this->app->getFrontController()->getRouter();
foreach ($this->routes as $name => $route) {
$router->addRoute($name, $route);
}
$router->addRoute( $router->addRoute(
$this->name . '_jsprovider', $this->name . '_jsprovider',
new Route( new Route(
@ -687,4 +702,19 @@ class Module
return $this; return $this;
} }
/**
* Add a route which will be added to the route chain
*
* @param string $name Name of the route
* @param Zend_Controller_Router_Route_Abstract $route Instance of the route
*
* @return self
* @see registerRoutes()
*/
protected function addRoute($name, Zend_Controller_Router_Route_Abstract $route)
{
$this->routes[$name] = $route;
return $this;
}
} }