⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 standard.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
            $controller = $request->getControllerName();            if (!$this->getParam('useDefaultControllerAlways') && !empty($controller)) {                require_once 'Zend/Controller/Dispatcher/Exception.php';                throw new Zend_Controller_Dispatcher_Exception('Invalid controller specified (' . $request->getControllerName() . ')');            }            $className = $this->getDefaultControllerClass($request);        } else {            $className = $this->getControllerClass($request);            if (!$className) {                $className = $this->getDefaultControllerClass($request);            }        }        /**         * Load the controller class file         */        $className = $this->loadClass($className);        /**         * Instantiate controller with request, response, and invocation         * arguments; throw exception if it's not an action controller         */        $controller = new $className($request, $this->getResponse(), $this->getParams());        if (!$controller instanceof Zend_Controller_Action) {            require_once 'Zend/Controller/Dispatcher/Exception.php';            throw new Zend_Controller_Dispatcher_Exception("Controller '$className' is not an instance of Zend_Controller_Action");        }        /**         * Retrieve the action name         */        $action = $this->getActionMethod($request);        /**         * Dispatch the method call         */        $request->setDispatched(true);        // by default, buffer output        $disableOb = $this->getParam('disableOutputBuffering');        $obLevel   = ob_get_level();        if (empty($disableOb)) {            ob_start();        }        try {            $controller->dispatch($action);        } 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);        }        // Destroy the page controller instance and reflection objects        $controller = null;    }    /**     * Load a controller class     *     * Attempts to load the controller class file from     * {@link getControllerDirectory()}.  If the controller belongs to a     * module, looks for the module prefix to the controller class.     *     * @param string $className     * @return string Class name loaded     * @throws Zend_Controller_Dispatcher_Exception if class not loaded     */    public function loadClass($className)    {        $finalClass  = $className;        if (($this->_defaultModule != $this->_curModule)             || $this->getParam('prefixDefaultModule'))         {            $finalClass = $this->formatClassName($this->_curModule, $className);        }        if (class_exists($finalClass, false)) {            return $finalClass;        }        $dispatchDir = $this->getDispatchDirectory();        $loadFile    = $dispatchDir . DIRECTORY_SEPARATOR . $this->classToFilename($className);        $dir         = dirname($loadFile);        $file        = basename($loadFile);        try {            Zend_Loader::loadFile($file, $dir, true);        } catch (Zend_Exception $e) {            require_once 'Zend/Controller/Dispatcher/Exception.php';            throw new Zend_Controller_Dispatcher_Exception('Cannot load controller class "' . $className . '" from file "' . $file . '" in directory "' . $dir . '"');        }        if (!class_exists($finalClass, false)) {            require_once 'Zend/Controller/Dispatcher/Exception.php';            throw new Zend_Controller_Dispatcher_Exception('Invalid controller class ("' . $finalClass . '")');        }        return $finalClass;    }    /**     * Get controller class name     *     * Try request first; if not found, try pulling from request parameter;     * if still not found, fallback to default     *     * @param Zend_Controller_Request_Abstract $request     * @return string|false Returns class name on success     */    public function getControllerClass(Zend_Controller_Request_Abstract $request)    {        $controllerName = $request->getControllerName();        if (empty($controllerName)) {            if (!$this->getParam('useDefaultControllerAlways')) {                return false;            }            $controllerName = $this->getDefaultControllerName();            $request->setControllerName($controllerName);        }        $className = $this->formatControllerName($controllerName);        $controllerDirs      = $this->getControllerDirectory();        $module = $request->getModuleName();        if ($this->isValidModule($module)) {            $this->_curModule    = $module;            $this->_curDirectory = $controllerDirs[$module];        } elseif ($this->isValidModule($this->_defaultModule)) {            $request->setModuleName($this->_defaultModule);            $this->_curModule    = $this->_defaultModule;            $this->_curDirectory = $controllerDirs[$this->_defaultModule];        } else {            require_once 'Zend/Controller/Exception.php';            throw new Zend_Controller_Exception('No default module defined for this application');        }        return $className;    }    /**     * Determine if a given module is valid     *     * @param string $module     * @return bool     */    public function isValidModule($module)    {        $controllerDir = $this->getControllerDirectory();        return (is_string($module) && isset($controllerDir[$module]));    }    /**     * Retrieve default controller class     *     * Determines whether the default controller to use lies within the     * requested module, or if the global default should be used.     *     * By default, will only use the module default unless that controller does     * not exist; if this is the case, it falls back to the default controller     * in the default module.     *     * @param Zend_Controller_Request_Abstract $request     * @return string     */    public function getDefaultControllerClass(Zend_Controller_Request_Abstract $request)    {        $controller = $this->getDefaultControllerName();        $default    = $this->formatControllerName($controller);        $request->setControllerName($controller)                ->setActionName(null);        $module              = $request->getModuleName();        $controllerDirs      = $this->getControllerDirectory();        $this->_curModule    = $this->_defaultModule;        $this->_curDirectory = $controllerDirs[$this->_defaultModule];        if ($this->isValidModule($module)) {            $found = false;            if (class_exists($default, false)) {                $found = true;            } else {                $moduleDir = $controllerDirs[$module];                $fileSpec  = $moduleDir . DIRECTORY_SEPARATOR . $this->classToFilename($default);                if (Zend_Loader::isReadable($fileSpec)) {                    $found = true;                    $this->_curDirectory = $moduleDir;                }            }            if ($found) {                $request->setModuleName($module);                $this->_curModule    = $this->formatModuleName($module);            }        } else {            $request->setModuleName($this->_defaultModule);        }        return $default;    }    /**     * Return the value of the currently selected dispatch directory (as set by     * {@link getController()})     *     * @return string     */    public function getDispatchDirectory()    {        return $this->_curDirectory;    }    /**     * Determine the action name     *     * First attempt to retrieve from request; then from request params     * using action key; default to default action     *     * Returns formatted action name     *     * @param Zend_Controller_Request_Abstract $request     * @return string     */    public function getActionMethod(Zend_Controller_Request_Abstract $request)    {        $action = $request->getActionName();        if (empty($action)) {            $action = $this->getDefaultAction();            $request->setActionName($action);        }        return $this->formatActionName($action);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -