| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Controller
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /** Zend_Loader */
- require_once 'Zend/Loader.php';
- /** Zend_Controller_Action_HelperBroker */
- require_once 'Zend/Controller/Action/HelperBroker.php';
- /** Zend_Controller_Plugin_Broker */
- require_once 'Zend/Controller/Plugin/Broker.php';
- /**
- * @category Zend
- * @package Zend_Controller
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Controller_Front
- {
- /**
- * Base URL
- * @var string
- */
- protected $_baseUrl = null;
- /**
- * Directory|ies where controllers are stored
- *
- * @var string|array
- */
- protected $_controllerDir = null;
- /**
- * Instance of Zend_Controller_Dispatcher_Interface
- * @var Zend_Controller_Dispatcher_Interface
- */
- protected $_dispatcher = null;
- /**
- * Singleton instance
- *
- * Marked only as protected to allow extension of the class. To extend,
- * simply override {@link getInstance()}.
- *
- * @var Zend_Controller_Front
- */
- protected static $_instance = null;
- /**
- * Array of invocation parameters to use when instantiating action
- * controllers
- * @var array
- */
- protected $_invokeParams = array();
- /**
- * Subdirectory within a module containing controllers; defaults to 'controllers'
- * @var string
- */
- protected $_moduleControllerDirectoryName = 'controllers';
- /**
- * Instance of Zend_Controller_Plugin_Broker
- * @var Zend_Controller_Plugin_Broker
- */
- protected $_plugins = null;
- /**
- * Instance of Zend_Controller_Request_Abstract
- * @var Zend_Controller_Request_Abstract
- */
- protected $_request = null;
- /**
- * Instance of Zend_Controller_Response_Abstract
- * @var Zend_Controller_Response_Abstract
- */
- protected $_response = null;
- /**
- * Whether or not to return the response prior to rendering output while in
- * {@link dispatch()}; default is to send headers and render output.
- * @var boolean
- */
- protected $_returnResponse = false;
- /**
- * Instance of Zend_Controller_Router_Interface
- * @var Zend_Controller_Router_Interface
- */
- protected $_router = null;
- /**
- * Whether or not exceptions encountered in {@link dispatch()} should be
- * thrown or trapped in the response object
- * @var boolean
- */
- protected $_throwExceptions = false;
- /**
- * Constructor
- *
- * Instantiate using {@link getInstance()}; front controller is a singleton
- * object.
- *
- * Instantiates the plugin broker.
- *
- * @return void
- */
- protected function __construct()
- {
- $this->_plugins = new Zend_Controller_Plugin_Broker();
- }
- /**
- * Enforce singleton; disallow cloning
- *
- * @return void
- */
- private function __clone()
- {
- }
- /**
- * Singleton instance
- *
- * @return Zend_Controller_Front
- */
- public static function getInstance()
- {
- if (null === self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- /**
- * Resets all object properties of the singleton instance
- *
- * Primarily used for testing; could be used to chain front controllers.
- *
- * Also resets action helper broker, clearing all registered helpers.
- *
- * @return void
- */
- public function resetInstance()
- {
- $reflection = new ReflectionObject($this);
- foreach ($reflection->getProperties() as $property) {
- $name = $property->getName();
- switch ($name) {
- case '_instance':
- break;
- case '_controllerDir':
- case '_invokeParams':
- $this->{$name} = array();
- break;
- case '_plugins':
- $this->{$name} = new Zend_Controller_Plugin_Broker();
- break;
- case '_throwExceptions':
- case '_returnResponse':
- $this->{$name} = false;
- break;
- case '_moduleControllerDirectoryName':
- $this->{$name} = 'controllers';
- break;
- default:
- $this->{$name} = null;
- break;
- }
- }
- Zend_Controller_Action_HelperBroker::resetHelpers();
- }
- /**
- * Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()
- *
- * In PHP 5.1.x, a call to a static method never populates $this -- so run()
- * may actually be called after setting up your front controller.
- *
- * @param string|array $controllerDirectory Path to Zend_Controller_Action
- * controller classes or array of such paths
- * @return void
- * @throws Zend_Controller_Exception if called from an object instance
- */
- public static function run($controllerDirectory)
- {
- self::getInstance()
- ->setControllerDirectory($controllerDirectory)
- ->dispatch();
- }
- /**
- * Add a controller directory to the controller directory stack
- *
- * If $args is presented and is a string, uses it for the array key mapping
- * to the directory specified.
- *
- * @param string $directory
- * @param string $module Optional argument; module with which to associate directory. If none provided, assumes 'default'
- * @return Zend_Controller_Front
- * @throws Zend_Controller_Exception if directory not found or readable
- */
- public function addControllerDirectory($directory, $module = null)
- {
- $this->getDispatcher()->addControllerDirectory($directory, $module);
- return $this;
- }
- /**
- * Set controller directory
- *
- * Stores controller directory(ies) in dispatcher. May be an array of
- * directories or a string containing a single directory.
- *
- * @param string|array $directory Path to Zend_Controller_Action controller
- * classes or array of such paths
- * @param string $module Optional module name to use with string $directory
- * @return Zend_Controller_Front
- */
- public function setControllerDirectory($directory, $module = null)
- {
- $this->getDispatcher()->setControllerDirectory($directory, $module);
- return $this;
- }
- /**
- * Retrieve controller directory
- *
- * Retrieves:
- * - Array of all controller directories if no $name passed
- * - String path if $name passed and exists as a key in controller directory array
- * - null if $name passed but does not exist in controller directory keys
- *
- * @param string $name Default null
- * @return array|string|null
- */
- public function getControllerDirectory($name = null)
- {
- return $this->getDispatcher()->getControllerDirectory($name);
- }
- /**
- * Remove a controller directory by module name
- *
- * @param string $module
- * @return bool
- */
- public function removeControllerDirectory($module)
- {
- return $this->getDispatcher()->removeControllerDirectory($module);
- }
- /**
- * Specify a directory as containing modules
- *
- * Iterates through the directory, adding any subdirectories as modules;
- * the subdirectory within each module named after {@link $_moduleControllerDirectoryName}
- * will be used as the controller directory path.
- *
- * @param string $path
- * @return Zend_Controller_Front
- */
- public function addModuleDirectory($path)
- {
- try{
- $dir = new DirectoryIterator($path);
- } catch(Exception $e) {
- require_once 'Zend/Controller/Exception.php';
- throw new Zend_Controller_Exception("Directory $path not readable", 0, $e);
- }
- foreach ($dir as $file) {
- if ($file->isDot() || !$file->isDir()) {
- continue;
- }
- $module = $file->getFilename();
- // Don't use SCCS directories as modules
- if (preg_match('/^[^a-z]/i', $module) || ('CVS' == $module)) {
- continue;
- }
- $moduleDir = $file->getPathname() . DIRECTORY_SEPARATOR . $this->getModuleControllerDirectoryName();
- $this->addControllerDirectory($moduleDir, $module);
- }
- return $this;
- }
- /**
- * Return the path to a module directory (but not the controllers directory within)
- *
- * @param string $module
- * @return string|null
- */
- public function getModuleDirectory($module = null)
- {
- if (null === $module) {
- $request = $this->getRequest();
- if (null !== $request) {
- $module = $this->getRequest()->getModuleName();
- }
- if (empty($module)) {
- $module = $this->getDispatcher()->getDefaultModule();
- }
- }
- $controllerDir = $this->getControllerDirectory($module);
- if ((null === $controllerDir) || !is_string($controllerDir)) {
- return null;
- }
- return dirname($controllerDir);
- }
- /**
- * Set the directory name within a module containing controllers
- *
- * @param string $name
- * @return Zend_Controller_Front
- */
- public function setModuleControllerDirectoryName($name = 'controllers')
- {
- $this->_moduleControllerDirectoryName = (string) $name;
- return $this;
- }
- /**
- * Return the directory name within a module containing controllers
- *
- * @return string
- */
- public function getModuleControllerDirectoryName()
- {
- return $this->_moduleControllerDirectoryName;
- }
- /**
- * Set the default controller (unformatted string)
- *
- * @param string $controller
- * @return Zend_Controller_Front
- */
- public function setDefaultControllerName($controller)
- {
- $dispatcher = $this->getDispatcher();
- $dispatcher->setDefaultControllerName($controller);
- return $this;
- }
- /**
- * Retrieve the default controller (unformatted string)
- *
- * @return string
- */
- public function getDefaultControllerName()
- {
- return $this->getDispatcher()->getDefaultControllerName();
- }
- /**
- * Set the default action (unformatted string)
- *
- * @param string $action
- * @return Zend_Controller_Front
- */
- public function setDefaultAction($action)
- {
- $dispatcher = $this->getDispatcher();
- $dispatcher->setDefaultAction($action);
- return $this;
- }
- /**
- * Retrieve the default action (unformatted string)
- *
- * @return string
- */
- public function getDefaultAction()
- {
- return $this->getDispatcher()->getDefaultAction();
- }
- /**
- * Set the default module name
- *
- * @param string $module
- * @return Zend_Controller_Front
- */
- public function setDefaultModule($module)
- {
- $dispatcher = $this->getDispatcher();
- $dispatcher->setDefaultModule($module);
- return $this;
- }
- /**
- * Retrieve the default module
- *
- * @return string
- */
- public function getDefaultModule()
- {
- return $this->getDispatcher()->getDefaultModule();
- }
- /**
- * Set request class/object
- *
- * Set the request object. The request holds the request environment.
- *
- * If a class name is provided, it will instantiate it
- *
- * @param string|Zend_Controller_Request_Abstract $request
- * @throws Zend_Controller_Exception if invalid request class
- * @return Zend_Controller_Front
- */
- public function setRequest($request)
- {
- if (is_string($request)) {
- if (!class_exists($request)) {
- require_once 'Zend/Loader.php';
- Zend_Loader::loadClass($request);
- }
- $request = new $request();
- }
- if (!$request instanceof Zend_Controller_Request_Abstract) {
- require_once 'Zend/Controller/Exception.php';
- throw new Zend_Controller_Exception('Invalid request class');
- }
- $this->_request = $request;
- return $this;
- }
- /**
- * Return the request object.
- *
- * @return null|Zend_Controller_Request_Abstract
- */
- public function getRequest()
- {
- return $this->_request;
- }
- /**
- * Set router class/object
- *
- * Set the router object. The router is responsible for mapping
- * the request to a controller and action.
- *
- * If a class name is provided, instantiates router with any parameters
- * registered via {@link setParam()} or {@link setParams()}.
- *
- * @param string|Zend_Controller_Router_Interface $router
- * @throws Zend_Controller_Exception if invalid router class
- * @return Zend_Controller_Front
- */
- public function setRouter($router)
- {
- if (is_string($router)) {
- if (!class_exists($router)) {
- require_once 'Zend/Loader.php';
- Zend_Loader::loadClass($router);
- }
- $router = new $router();
- }
- if (!$router instanceof Zend_Controller_Router_Interface) {
- require_once 'Zend/Controller/Exception.php';
- throw new Zend_Controller_Exception('Invalid router class');
- }
- $router->setFrontController($this);
- $this->_router = $router;
- return $this;
- }
- /**
- * Return the router object.
- *
- * Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.
- *
- * @return Zend_Controller_Router_Interface
- */
- public function getRouter()
- {
- if (null == $this->_router) {
- require_once 'Zend/Controller/Router/Rewrite.php';
- $this->setRouter(new Zend_Controller_Router_Rewrite());
- }
- return $this->_router;
- }
- /**
- * Set the base URL used for requests
- *
- * Use to set the base URL segment of the REQUEST_URI to use when
- * determining PATH_INFO, etc. Examples:
- * - /admin
- * - /myapp
- * - /subdir/index.php
- *
- * Note that the URL should not include the full URI. Do not use:
- * - http://example.com/admin
- * - http://example.com/myapp
- * - http://example.com/subdir/index.php
- *
- * If a null value is passed, this can be used as well for autodiscovery (default).
- *
- * @param string $base
- * @return Zend_Controller_Front
- * @throws Zend_Controller_Exception for non-string $base
- */
- public function setBaseUrl($base = null)
- {
- if (!is_string($base) && (null !== $base)) {
- require_once 'Zend/Controller/Exception.php';
- throw new Zend_Controller_Exception('Rewrite base must be a string');
- }
- $this->_baseUrl = $base;
- if ((null !== ($request = $this->getRequest())) && (method_exists($request, 'setBaseUrl'))) {
- $request->setBaseUrl($base);
- }
- return $this;
- }
- /**
- * Retrieve the currently set base URL
- *
- * @return string
- */
- public function getBaseUrl()
- {
- $request = $this->getRequest();
- if ((null !== $request) && method_exists($request, 'getBaseUrl')) {
- return $request->getBaseUrl();
- }
- return $this->_baseUrl;
- }
- /**
- * Set the dispatcher object. The dispatcher is responsible for
- * taking a Zend_Controller_Dispatcher_Token object, instantiating the controller, and
- * call the action method of the controller.
- *
- * @param Zend_Controller_Dispatcher_Interface $dispatcher
- * @return Zend_Controller_Front
- */
- public function setDispatcher(Zend_Controller_Dispatcher_Interface $dispatcher)
- {
- $this->_dispatcher = $dispatcher;
- return $this;
- }
- /**
- * Return the dispatcher object.
- *
- * @return Zend_Controller_Dispatcher_Interface
- */
- public function getDispatcher()
- {
- /**
- * Instantiate the default dispatcher if one was not set.
- */
- if (!$this->_dispatcher instanceof Zend_Controller_Dispatcher_Interface) {
- require_once 'Zend/Controller/Dispatcher/Standard.php';
- $this->_dispatcher = new Zend_Controller_Dispatcher_Standard();
- }
- return $this->_dispatcher;
- }
- /**
- * Set response class/object
- *
- * Set the response object. The response is a container for action
- * responses and headers. Usage is optional.
- *
- * If a class name is provided, instantiates a response object.
- *
- * @param string|Zend_Controller_Response_Abstract $response
- * @throws Zend_Controller_Exception if invalid response class
- * @return Zend_Controller_Front
- */
- public function setResponse($response)
- {
- if (is_string($response)) {
- if (!class_exists($response)) {
- require_once 'Zend/Loader.php';
- Zend_Loader::loadClass($response);
- }
- $response = new $response();
- }
- if (!$response instanceof Zend_Controller_Response_Abstract) {
- require_once 'Zend/Controller/Exception.php';
- throw new Zend_Controller_Exception('Invalid response class');
- }
- $this->_response = $response;
- return $this;
- }
- /**
- * Return the response object.
- *
- * @return null|Zend_Controller_Response_Abstract
- */
- public function getResponse()
- {
- return $this->_response;
- }
- /**
- * Add or modify a parameter to use when instantiating an action controller
- *
- * @param string $name
- * @param mixed $value
- * @return Zend_Controller_Front
- */
- public function setParam($name, $value)
- {
- $name = (string) $name;
- $this->_invokeParams[$name] = $value;
- return $this;
- }
- /**
- * Set parameters to pass to action controller constructors
- *
- * @param array $params
- * @return Zend_Controller_Front
- */
- public function setParams(array $params)
- {
- $this->_invokeParams = array_merge($this->_invokeParams, $params);
- return $this;
- }
- /**
- * Retrieve a single parameter from the controller parameter stack
- *
- * @param string $name
- * @return mixed
- */
- public function getParam($name)
- {
- if(isset($this->_invokeParams[$name])) {
- return $this->_invokeParams[$name];
- }
- return null;
- }
- /**
- * Retrieve action controller instantiation parameters
- *
- * @return array
- */
- public function getParams()
- {
- return $this->_invokeParams;
- }
- /**
- * Clear the controller parameter stack
- *
- * By default, clears all parameters. If a parameter name is given, clears
- * only that parameter; if an array of parameter names is provided, clears
- * each.
- *
- * @param null|string|array single key or array of keys for params to clear
- * @return Zend_Controller_Front
- */
- public function clearParams($name = null)
- {
- if (null === $name) {
- $this->_invokeParams = array();
- } elseif (is_string($name) && isset($this->_invokeParams[$name])) {
- unset($this->_invokeParams[$name]);
- } elseif (is_array($name)) {
- foreach ($name as $key) {
- if (is_string($key) && isset($this->_invokeParams[$key])) {
- unset($this->_invokeParams[$key]);
- }
- }
- }
- return $this;
- }
- /**
- * Register a plugin.
- *
- * @param Zend_Controller_Plugin_Abstract $plugin
- * @param int $stackIndex Optional; stack index for plugin
- * @return Zend_Controller_Front
- */
- public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null)
- {
- $this->_plugins->registerPlugin($plugin, $stackIndex);
- return $this;
- }
- /**
- * Unregister a plugin.
- *
- * @param string|Zend_Controller_Plugin_Abstract $plugin Plugin class or object to unregister
- * @return Zend_Controller_Front
- */
- public function unregisterPlugin($plugin)
- {
- $this->_plugins->unregisterPlugin($plugin);
- return $this;
- }
- /**
- * Is a particular plugin registered?
- *
- * @param string $class
- * @return bool
- */
- public function hasPlugin($class)
- {
- return $this->_plugins->hasPlugin($class);
- }
- /**
- * Retrieve a plugin or plugins by class
- *
- * @param string $class
- * @return false|Zend_Controller_Plugin_Abstract|array
- */
- public function getPlugin($class)
- {
- return $this->_plugins->getPlugin($class);
- }
- /**
- * Retrieve all plugins
- *
- * @return array
- */
- public function getPlugins()
- {
- return $this->_plugins->getPlugins();
- }
- /**
- * Set the throwExceptions flag and retrieve current status
- *
- * Set whether exceptions encounted in the dispatch loop should be thrown
- * or caught and trapped in the response object.
- *
- * Default behaviour is to trap them in the response object; call this
- * method to have them thrown.
- *
- * Passing no value will return the current value of the flag; passing a
- * boolean true or false value will set the flag and return the current
- * object instance.
- *
- * @param boolean $flag Defaults to null (return flag state)
- * @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
- */
- public function throwExceptions($flag = null)
- {
- if ($flag !== null) {
- $this->_throwExceptions = (bool) $flag;
- return $this;
- }
- return $this->_throwExceptions;
- }
- /**
- * Set whether {@link dispatch()} should return the response without first
- * rendering output. By default, output is rendered and dispatch() returns
- * nothing.
- *
- * @param boolean $flag
- * @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
- */
- public function returnResponse($flag = null)
- {
- if (true === $flag) {
- $this->_returnResponse = true;
- return $this;
- } elseif (false === $flag) {
- $this->_returnResponse = false;
- return $this;
- }
- return $this->_returnResponse;
- }
- /**
- * Dispatch an HTTP request to a controller/action.
- *
- * @param Zend_Controller_Request_Abstract|null $request
- * @param Zend_Controller_Response_Abstract|null $response
- * @return void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
- */
- public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
- {
- if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) {
- // Register with stack index of 100
- require_once 'Zend/Controller/Plugin/ErrorHandler.php';
- $this->_plugins->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100);
- }
- if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
- require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
- Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, new Zend_Controller_Action_Helper_ViewRenderer());
- }
- /**
- * Instantiate default request object (HTTP version) if none provided
- */
- if (null !== $request) {
- $this->setRequest($request);
- } elseif ((null === $request) && (null === ($request = $this->getRequest()))) {
- require_once 'Zend/Controller/Request/Http.php';
- $request = new Zend_Controller_Request_Http();
- $this->setRequest($request);
- }
- /**
- * Set base URL of request object, if available
- */
- if (is_callable(array($this->_request, 'setBaseUrl'))) {
- if (null !== $this->_baseUrl) {
- $this->_request->setBaseUrl($this->_baseUrl);
- }
- }
- /**
- * Instantiate default response object (HTTP version) if none provided
- */
- if (null !== $response) {
- $this->setResponse($response);
- } elseif ((null === $this->_response) && (null === ($this->_response = $this->getResponse()))) {
- require_once 'Zend/Controller/Response/Http.php';
- $response = new Zend_Controller_Response_Http();
- $this->setResponse($response);
- }
- /**
- * Register request and response objects with plugin broker
- */
- $this->_plugins
- ->setRequest($this->_request)
- ->setResponse($this->_response);
- /**
- * Initialize router
- */
- $router = $this->getRouter();
- $router->setParams($this->getParams());
- /**
- * Initialize dispatcher
- */
- $dispatcher = $this->getDispatcher();
- $dispatcher->setParams($this->getParams())
- ->setResponse($this->_response);
- // Begin dispatch
- try {
- /**
- * Route request to controller/action, if a router is provided
- */
- /**
- * Notify plugins of router startup
- */
- $this->_plugins->routeStartup($this->_request);
- try {
- $router->route($this->_request);
- } catch (Exception $e) {
- if ($this->throwExceptions()) {
- throw $e;
- }
- $this->_response->setException($e);
- }
- /**
- * Notify plugins of router completion
- */
- $this->_plugins->routeShutdown($this->_request);
- /**
- * Notify plugins of dispatch loop startup
- */
- $this->_plugins->dispatchLoopStartup($this->_request);
- /**
- * Attempt to dispatch the controller/action. If the $this->_request
- * indicates that it needs to be dispatched, move to the next
- * action in the request.
- */
- do {
- $this->_request->setDispatched(true);
- /**
- * Notify plugins of dispatch startup
- */
- $this->_plugins->preDispatch($this->_request);
- /**
- * Skip requested action if preDispatch() has reset it
- */
- if (!$this->_request->isDispatched()) {
- continue;
- }
- /**
- * Dispatch request
- */
- try {
- $dispatcher->dispatch($this->_request, $this->_response);
- } catch (Exception $e) {
- if ($this->throwExceptions()) {
- throw $e;
- }
- $this->_response->setException($e);
- }
- /**
- * Notify plugins of dispatch completion
- */
- $this->_plugins->postDispatch($this->_request);
- } while (!$this->_request->isDispatched());
- } catch (Exception $e) {
- if ($this->throwExceptions()) {
- throw $e;
- }
- $this->_response->setException($e);
- }
- /**
- * Notify plugins of dispatch loop completion
- */
- try {
- $this->_plugins->dispatchLoopShutdown();
- } catch (Exception $e) {
- if ($this->throwExceptions()) {
- throw $e;
- }
- $this->_response->setException($e);
- }
- if ($this->returnResponse()) {
- return $this->_response;
- }
- $this->_response->sendResponse();
- }
- }
|