//自定义zend_controller_dispatcher_standard派遣器 <?php /** * 自定义派遣器 Zend_Controller_Dispatcher * @author wolf [Email: 116311316@qq.com] * @since 2010-09-30 */ class Custom_Controller_Dispatcher implements Custom_Controller_Dispatcher_Interface { /** * Controller directory(ies) * @var array */ protected $_controllerDirectory = array (); /** * 实例化控制器的过程 * require_once './application/default/controllers/indexcontroller.php' * $controller=new IndexController(); * $controller->index(); * @param Zend_Controller_Request $resquest * */ public function dispatch(Custom_Controller_Request_Http $request) { /** * @var $controller Custom_Controller_Request_Http */ $controller = $request->getControllerName () . "controller"; $module = $request->getModuleName (); $loadFile = "./application" . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . "controllers" . DIRECTORY_SEPARATOR . $controller . ".php"; //检测加载文件 if (Zend_Loader::isReadable ( $loadFile )) { include_once $loadFile; } else { require_once 'Zend/Controller/Dispatcher/Exception.php'; throw new Zend_Controller_Dispatcher_Exception ( 'Cannot load controller class "' . $controller . '" from file "' . $loadFile . "'" ); } $controllerclass = new $controller ( $request ); /** * Retrieve the action name */ $action = $request->getActionName (); $controllerclass->$action (); // Destroy the page controller instance and reflection objects $controller = null; } /** * Add a single path to the controller directory stack * 只能添加一个 * @param string $path * @param string $module * @return Zeed_Controller_Dispatcher */ public function addControllerDirectory($path, $module = null) { if (null === $module) { $module = $this->_defaultModule; } $module = ( string ) $module; $path = rtrim ( ( string ) $path, '///' ); $this->_controllerDirectory [$module] = $path; return $this; } /** * 获得module目录 DirectoryIterator * @param string $module Module name * @return array|string Returns array of all directories by default, single module directory if module argument provided */ public function getControllerDirectory($module = null) { if (null === $module) { return $this->_controllerDirectory; } $module = ( string ) $module; if (array_key_exists ( $module, $this->_controllerDirectory )) { return $this->_controllerDirectory [$module]; } return null; } /** * Determine if a given module is valid 在默认路由协议中 * * @param string $module * @return bool */ public function isValidModule($module) { if (! is_string ( $module )) { return false; } if (array_key_exists ( strtolower ( $module ), array_change_key_case ( $this->getControllerDirectory (), CASE_LOWER ) )) { return true; } return false; } } // End ^ LF ^ UTF-8