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

📄 contextswitch.php

📁 zend的加强包 zend的加强包
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        if (!isset($this->_contexts[$type])) {            /**             * @see Zend_Controller_Action_Exception             */            require_once 'Zend/Controller/Action/Exception.php';            throw new Zend_Controller_Action_Exception(sprintf('Cannot retrieve suffix; invalid context type "%s"', $type));        }        return $this->_contexts[$type]['suffix'];    }    /**     * Does the given context exist?     *      * @param  string  $context      * @param  boolean $throwException      * @throws Zend_Controller_Action_Exception if context does not exist and throwException is true     * @return bool     */    public function hasContext($context, $throwException = false)    {        if (is_string($context)) {            if (isset($this->_contexts[$context])) {                return true;            }        } elseif (is_array($context)) {            $error = false;            foreach ($context as $test) {                if (!isset($this->_contexts[$test])) {                    $error = (string) $test;                    break;                }            }            if (false === $error) {                return true;            }            $context = $error;        } elseif (true === $context) {            return true;        }        if ($throwException) {            /**             * @see Zend_Controller_Action_Exception             */            require_once 'Zend/Controller/Action/Exception.php';            throw new Zend_Controller_Action_Exception(sprintf('Context "%s" does not exist', $context));        }        return false;    }    /**     * Add header to context     *      * @param  string $context      * @param  string $header      * @param  string $content     * @throws Zend_Controller_Action_Exception      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function addHeader($context, $header, $content)    {        $context = (string) $context;        $this->hasContext($context, true);        $header  = (string) $header;        $content = (string) $content;        if (isset($this->_contexts[$context]['headers'][$header])) {            /**             * @see Zend_Controller_Action_Exception             */            require_once 'Zend/Controller/Action/Exception.php';            throw new Zend_Controller_Action_Exception(sprintf('Cannot add "%s" header to context "%s": already exists', $header, $context));        }        $this->_contexts[$context]['headers'][$header] = $content;        return $this;    }     /**     * Customize response header to use when switching context     *      * Passing an empty header value to the setters disables the response     * header.     *     * @param  string $type   Context type for which to set suffix     * @param  string $header Header to set     * @param  string $content Header content     * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */     public function setHeader($context, $header, $content)    {        $this->hasContext($context, true);        $context = (string) $context;        $header  = (string) $header;        $content = (string) $content;        $this->_contexts[$context]['headers'][$header] = $content;        return $this;    }    /**     * Add multiple headers at once for a given context     *      * @param  string $context      * @param  array  $headers      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function addHeaders($context, array $headers)    {        foreach ($headers as $header => $content) {            $this->addHeader($context, $header, $content);        }        return $this;    }    /**     * Set headers from context => headers pairs     *      * @param  array $options      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    protected function _setHeaders(array $options)    {        foreach ($options as $context => $headers) {            if (!is_array($headers)) {                continue;            }            $this->setHeaders($context, $headers);        }        return $this;    }    /**     * Set multiple headers at once for a given context     *      * @param  string $context      * @param  array  $headers      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function setHeaders($context, array $headers)    {        $this->clearHeaders($context);        foreach ($headers as $header => $content) {            $this->setHeader($context, $header, $content);        }        return $this;    }    /**     * Retrieve context header     *     * Returns the value of a given header for a given context type     *      * @param  string $context     * @param  string $header     * @return string|null     */    public function getHeader($context, $header)    {        $this->hasContext($context, true);        $context = (string) $context;        $header  = (string) $header;        if (isset($this->_contexts[$context]['headers'][$header])) {            return $this->_contexts[$context]['headers'][$header];        }        return null;    }    /**     * Retrieve context headers     *     * Returns all headers for a context as key/value pairs     *      * @param  string $context     * @return array     */    public function getHeaders($context)    {        $this->hasContext($context, true);        $context = (string) $context;        return $this->_contexts[$context]['headers'];    }    /**     * Remove a single header from a context     *      * @param  string $context      * @param  string $header      * @return boolean     */    public function removeHeader($context, $header)    {        $this->hasContext($context, true);        $context = (string) $context;        $header  = (string) $header;        if (isset($this->_contexts[$context]['headers'][$header])) {            unset($this->_contexts[$context]['headers'][$header]);            return true;        }        return false;    }    /**     * Clear all headers for a given context     *      * @param  string $context      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function clearHeaders($context)    {        $this->hasContext($context, true);        $context = (string) $context;        $this->_contexts[$context]['headers'] = array();        return $this;    }    /**     * Validate trigger and return in normalized form     *      * @param  string $trigger     * @throws Zend_Controller_Action_Exception      * @return string     */    protected function _validateTrigger($trigger)    {        $trigger = strtoupper($trigger);        if ('TRIGGER_' !== substr($trigger, 0, 8)) {            $trigger = 'TRIGGER_' . $trigger;        }        if (!in_array($trigger, array(self::TRIGGER_INIT, self::TRIGGER_POST))) {            /**             * @see Zend_Controller_Action_Exception             */            require_once 'Zend/Controller/Action/Exception.php';            throw new Zend_Controller_Action_Exception(sprintf('Invalid trigger "%s"', $trigger));        }        return $trigger;    }    /**     * Set a callback for a given context and trigger     *      * @param  string       $context      * @param  string       $trigger      * @param  string|array $callback      * @throws Zend_Controller_Action_Exception     * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function setCallback($context, $trigger, $callback)    {        $this->hasContext($context, true);        $trigger = $this->_validateTrigger($trigger);        if (!is_string($callback)) {            if (!is_array($callback) || (2 != count($callback))) {                /**                 * @see Zend_Controller_Action_Exception                 */                require_once 'Zend/Controller/Action/Exception.php';                throw new Zend_Controller_Action_Exception('Invalid callback specified');            }        }        $this->_contexts[$context]['callbacks'][$trigger] = $callback;        return $this;    }    /**     * Set callbacks from array of context => callbacks pairs     *      * @param  array $options      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    protected function _setCallbacks(array $options)    {        foreach ($options as $context => $callbacks) {            if (!is_array($callbacks)) {                continue;            }            $this->setCallbacks($context, $callbacks);        }        return $this;    }    /**     * Set callbacks for a given context     *     * Callbacks should be in trigger/callback pairs.     *      * @param  string $context      * @param  array  $callbacks      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function setCallbacks($context, array $callbacks)    {        $this->hasContext($context, true);        $context = (string) $context;        if (!isset($this->_contexts[$context]['callbacks'])) {            $this->_contexts[$context]['callbacks'] = array();        }        foreach ($callbacks as $trigger => $callback) {            $this->setCallback($context, $trigger, $callback);        }        return $this;    }    /**     * Get a single callback for a given context and trigger     *      * @param  string $context      * @param  string $trigger      * @return string|array|null     */    public function getCallback($context, $trigger)    {        $this->hasContext($context, true);        $trigger = $this->_validateTrigger($trigger);        if (isset($this->_contexts[$context]['callbacks'][$trigger])) {            return $this->_contexts[$context]['callbacks'][$trigger];        }        return null;    }    /**     * Get all callbacks for a given context     *      * @param  string $context      * @return array     */    public function getCallbacks($context)    {        $this->hasContext($context, true);        return $this->_contexts[$context]['callbacks'];    }    /**     * Clear a callback for a given context and trigger     *      * @param  string $context      * @param  string $trigger      * @return boolean     */    public function removeCallback($context, $trigger)    {        $this->hasContext($context, true);        $trigger = $this->_validateTrigger($trigger);        if (isset($this->_contexts[$context]['callbacks'][$trigger])) {            unset($this->_contexts[$context]['callbacks'][$trigger]);            return true;        }        return false;    }    /**     * Clear all callbacks for a given context     *      * @param  string $context      * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */    public function clearCallbacks($context)    {        $this->hasContext($context, true);        $this->_contexts[$context]['callbacks'] = array();        return $this;    }    /**     * Set name of parameter to use when determining context format     *     * @param  string $name     * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */     public function setContextParam($name)    {        $this->_contextParam = (string) $name;        return $this;    }    /**     * Return context format request parameter name     *      * @return string     */    public function getContextParam()    {        return $this->_contextParam;    }     /**     * Indicate default context to use when no context format provided     *     * @param  string $type     * @throws Zend_Controller_Action_Exception     * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */     public function setDefaultContext($type)    {        if (!isset($this->_contexts[$type])) {            /**             * @see Zend_Controller_Action_Exception             */            require_once 'Zend/Controller/Action/Exception.php';            throw new Zend_Controller_Action_Exception(sprintf('Cannot set default context; invalid context type "%s"', $type));        }        $this->_defaultContext = $type;        return $this;    }    /**     * Return default context     *      * @return string     */    public function getDefaultContext()    {        return $this->_defaultContext;    }     /**     * Set flag indicating if layout should be disabled     *     * @param  boolean $flag     * @return Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface     */     public function setAutoDisableLayout($flag)    {        $this->_disableLayout = ($flag) ? true : false;        return $this;    }    /**     * Retrieve auto layout disable flag     *      * @return boolean     */    public function getAutoDisableLayout()    {        return $this->_disableLayout;

⌨️ 快捷键说明

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