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

📄 form.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?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_Form * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License *//** Zend_Validate_Interface */require_once 'Zend/Validate/Interface.php';/** * Zend_Form *  * @category   Zend * @package    Zend_Form * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License * @version    $Id: Form.php 8996 2008-03-22 16:59:06Z matthew $ */class Zend_Form implements Iterator, Countable, Zend_Validate_Interface{    /**#@+     * Plugin loader type constants     */    const DECORATOR = 'DECORATOR';    const ELEMENT = 'ELEMENT';    /**#@-*/    /**#@+     * Method type constants     */    const METHOD_DELETE = 'delete';    const METHOD_GET    = 'get';    const METHOD_POST   = 'post';    const METHOD_PUT    = 'put';    /**#@-*/    /**     * Form metadata and attributes     * @var array     */    protected $_attribs = array();    /**     * Decorators for rendering     * @var array     */    protected $_decorators = array();    /**     * Default display group class     * @var string     */    protected $_defaultDisplayGroupClass = 'Zend_Form_DisplayGroup';    /**     * Form description     * @var string     */    protected $_description;    /**     * Should we disable loading the default decorators?     * @var bool     */    protected $_disableLoadDefaultDecorators = false;    /**     * Display group prefix paths     * @var array     */    protected $_displayGroupPrefixPaths = array();    /**     * Groups of elements grouped for display purposes     * @var array     */    protected $_displayGroups = array();    /**     * Prefix paths to use when creating elements     * @var array     */    protected $_elementPrefixPaths = array();    /**     * Form elements     * @var array     */    protected $_elements = array();    /**     * Array to which elements belong (if any)     * @var string     */    protected $_elementsBelongTo;    /**     * Are there errors in the form?     * @var bool     */    protected $_errorsExist = false;    /**     * Form order     * @var int|null     */    protected $_formOrder;    /**     * Whether or not form elements are members of an array     * @var bool     */    protected $_isArray = false;    /**     * Form legend     * @var string     */    protected $_legend;    /**     * Plugin loaders     * @var array     */    protected $_loaders = array();    /**     * Allowed form methods     * @var array     */    protected $_methods = array('delete', 'get', 'post', 'put');    /**     * Order in which to display and iterate elements     * @var array     */    protected $_order = array();    /**     * Whether internal order has been updated or not     * @var bool     */    protected $_orderUpdated = false;    /**     * Sub form prefix paths     * @var array     */    protected $_subFormPrefixPaths = array();    /**     * Sub forms     * @var array     */    protected $_subForms = array();    /**     * @var Zend_Translate     */    protected $_translator;    /**     * Global default translation adapter     * @var Zend_Translate     */    protected static $_translatorDefault;    /**     * is the translator disabled?     * @var bool     */    protected $_translatorDisabled = false;    /**     * @var Zend_View_Interface     */    protected $_view;    /**     * Constructor     *     * Registers form view helper as decorator     *      * @param mixed $options      * @return void     */    public function __construct($options = null)    {        if (is_array($options)) {            $this->setOptions($options);        } elseif ($options instanceof Zend_Config) {            $this->setConfig($options);        }        // Extensions...        $this->init();        $this->loadDefaultDecorators();    }    /**     * Initialize form (used by extending classes)     *      * @return void     */    public function init()    {    }    /**     * Set form state from options array     *      * @param  array $options      * @return Zend_Form     */    public function setOptions(array $options)    {        if (isset($options['prefixPath'])) {            $this->addPrefixPaths($options['prefixPath']);            unset($options['prefixPath']);        }        if (isset($options['elementPrefixPath'])) {                                      $this->addElementPrefixPaths($options['elementPrefixPath']);                  unset($options['elementPrefixPath']);                                     }        if (isset($options['elements'])) {            $this->setElements($options['elements']);            unset($options['elements']);        }        if (isset($options['elementDecorators'])) {            $elementDecorators = $options['elementDecorators'];            unset($options['elementDecorators']);        }        if (isset($options['defaultDisplayGroupClass'])) {            $this->setDefaultDisplayGroupClass($options['defaultDisplayGroupClass']);            unset($options['defaultDisplayGroupClass']);        }        if (isset($options['displayGroupDecorators'])) {            $displayGroupDecorators = $options['displayGroupDecorators'];            unset($options['displayGroupDecorators']);        }        if (isset($options['elementsBelongTo'])) {            $elementsBelongTo = $options['elementsBelongTo'];            unset($options['elementsBelongTo']);        }        if (isset($options['attribs'])) {            $this->addAttribs($options['attribs']);            unset($options['attribs']);        }        $forbidden = array(            'Options', 'Config', 'PluginLoader', 'SubForms', 'View', 'Translator',            'Attrib', 'Default',        );        foreach ($options as $key => $value) {            $normalized = ucfirst($key);            if (in_array($normalized, $forbidden)) {                continue;            }            $method = 'set' . $normalized;            if (method_exists($this, $method)) {                $this->$method($value);            } else {                $this->setAttrib($key, $value);            }        }        if (isset($elementDecorators)) {            $this->setElementDecorators($elementDecorators);        }        if (isset($displayGroupDecorators)) {            $this->setDisplayGroupDecorators($displayGroupDecorators);        }        if (isset($elementsBelongTo)) {            $this->setElementsBelongTo($elementsBelongTo);        }        return $this;    }    /**     * Set form state from config object     *      * @param  Zend_Config $config      * @return Zend_Form     */    public function setConfig(Zend_Config $config)    {        return $this->setOptions($config->toArray());    }     // Loaders     /**     * Set plugin loaders for use with decorators and elements     *      * @param  Zend_Loader_PluginLoader_Interface $loader      * @param  string $type 'decorator' or 'element'     * @return Zend_Form     * @throws Zend_Form_Exception on invalid type     */    public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type = null)    {        $type = strtoupper($type);        switch ($type) {            case self::DECORATOR:            case self::ELEMENT:                $this->_loaders[$type] = $loader;                return $this;            default:                require_once 'Zend/Form/Exception.php';                throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));        }    }    /**     * Retrieve plugin loader for given type     *     * $type may be one of:     * - decorator     * - element     *     * If a plugin loader does not exist for the given type, defaults are      * created.     *      * @param  string $type      * @return Zend_Loader_PluginLoader_Interface     */    public function getPluginLoader($type = null)    {        $type = strtoupper($type);        if (!isset($this->_loaders[$type])) {            switch ($type) {                case self::DECORATOR:                    $prefixSegment = 'Form_Decorator';                    $pathSegment   = 'Form/Decorator';                    break;                case self::ELEMENT:                    $prefixSegment = 'Form_Element';                    $pathSegment   = 'Form/Element';                    break;                default:                    require_once 'Zend/Form/Exception.php';                    throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));            }            require_once 'Zend/Loader/PluginLoader.php';            $this->_loaders[$type] = new Zend_Loader_PluginLoader(                array('Zend_' . $prefixSegment . '_' => 'Zend/' . $pathSegment . '/')            );        }        return $this->_loaders[$type];    }    /**     * Add prefix path for plugin loader     *     * If no $type specified, assumes it is a base path for both filters and      * validators, and sets each according to the following rules:     * - decorators: $prefix = $prefix . '_Decorator'     * - elements: $prefix = $prefix . '_Element'     *     * Otherwise, the path prefix is set on the appropriate plugin loader.     *     * If $type is 'decorators', sets the path in the decorator plugin loader      * for all elements. Additionally, if no $type is provided,      * {@link Zend_Form_Element::addPrefixPath()} is called on each element.     *      * @param  string $path      * @return Zend_Form     * @throws Zend_Form_Exception for invalid type     */    public function addPrefixPath($prefix, $path, $type = null)     {        $type = strtoupper($type);        switch ($type) {            case self::DECORATOR:            case self::ELEMENT:                $loader = $this->getPluginLoader($type);                $loader->addPrefixPath($prefix, $path);                return $this;            case null:                $prefix = rtrim($prefix, '_');                $path   = rtrim($path, DIRECTORY_SEPARATOR);                foreach (array(self::DECORATOR, self::ELEMENT) as $type) {                    $cType        = ucfirst(strtolower($type));                    $pluginPath   = $path . DIRECTORY_SEPARATOR . $cType . DIRECTORY_SEPARATOR;                    $pluginPrefix = $prefix . '_' . $cType;                    $loader       = $this->getPluginLoader($type);                    $loader->addPrefixPath($pluginPrefix, $pluginPath);                }                return $this;            default:                require_once 'Zend/Form/Exception.php';                throw new Zend_Form_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));        }    }    /**     * Add many prefix paths at once     *      * @param  array $spec      * @return Zend_Form_Element     */    public function addPrefixPaths(array $spec)    {        if (isset($spec['prefix']) && isset($spec['path'])) {            return $this->addPrefixPath($spec['prefix'], $spec['path']);        }         foreach ($spec as $type => $paths) {            if (is_numeric($type) && is_array($paths)) {                $type = null;                if (isset($paths['prefix']) && isset($paths['path'])) {                    if (isset($paths['type'])) {                        $type = $paths['type'];                    }                    $this->addPrefixPath($paths['prefix'], $paths['path'], $type);                }            } elseif (!is_numeric($type)) {                if (!isset($paths['prefix']) || !isset($paths['path'])) {                    continue;                }                $this->addPrefixPath($paths['prefix'], $paths['path'], $type);            }        }        return $this;    }    /**     * Add prefix path for all elements     *      * @param  string $prefix      * @param  string $path      * @param  string $type      * @return Zend_Form     */    public function addElementPrefixPath($prefix, $path, $type = null)    {        $this->_elementPrefixPaths[] = array(            'prefix' => $prefix,             'path'   => $path,             'type'   => $type,        );        foreach ($this->getElements() as $element) {            $element->addPrefixPath($prefix, $path, $type);        }        return $this;    }    /**

⌨️ 快捷键说明

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