Dispatcher_Interface) {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Dispatcher.php';
$this->_dispatcher = new Zend_Controller_Dispatcher();
}
return $this->_dispatcher;
}
/**
* Register a plugin.
*
* @param Zend_Controller_Plugin_Interface $plugin
* @return Zend_Controller_Front
*/
public function registerPlugin(Zend_Controller_Plugin_Interface $plugin)
{
$this->_plugins->registerPlugin($plugin);
return $this;
}
/**
* Unregister a plugin.
*
* @return Zend_Controller_Front
*/
public function unregisterPlugin(Zend_Controller_Plugin_Interface $plugin)
{
$this->_plugins->unregisterPlugin($plugin);
return $this;
}
/**
* Dispatch an HTTP request to a controller/action.
*/
public function dispatch()
{
/* @var $action Zend_Controller_Dispatcher_Token */
try {
// notify plugins that the router is startup up
$this->_plugins->routeStartup();
/**
* Route a URI to a controller/action. If the route cannot be
* made, an exception is thrown.
*/
try {
$action = $this->getRouter()->route($this->getDispatcher());
} catch(Zend_Controller_Router_Exception $e) {
// Failed routing (basically a 404, no controller found)
// change the action
$action = new Zend_Controller_Dispatcher_Token('index', 'noRoute', array('error' => $e));
}
// notify plugins that the router is shutting down
$action = $this->_plugins->routeShutdown($action);
// notify plugins that the dispatch loop is starting up
$action = $this->_plugins->dispatchLoopStartup($action);
/**
* Attempt to dispatch to the controller/action. On return, either
* false will be given to indicate completion, or Zend_Controller_Dispatcher_Token will be
* given to indicate a forward to another controller/action must
* be performed.
*/
while ($action instanceof Zend_Controller_Dispatcher_Token) {
// notify plugins that a dispatch is about to occur
$action = $this->_plugins->preDispatch($action);
$action = $this->getDispatcher()->dispatch($action);
// notify plugins that the dispatch has finish
$action = $this->_plugins->postDispatch($action);
}
// notify plugins that the dispatch loop is shutting down
$this->_plugins->dispatchLoopShutdown();
} catch (Exception $e) {
// @todo exception processing
//echo('EXCEPTION: ' . $e->getMessage());
throw $e;
}
}
}