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

📄 input.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?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_Filter * @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: Input.php 8928 2008-03-20 19:41:41Z thomas $ *//** * @see Zend_Loader */require_once 'Zend/Loader.php';/** * @see Zend_Filter */require_once 'Zend/Filter.php';/** * @see Zend_Validate */require_once 'Zend/Validate.php';/** * @category   Zend * @package    Zend_Filter * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */class Zend_Filter_Input{    const ALLOW_EMPTY       = 'allowEmpty';    const BREAK_CHAIN       = 'breakChainOnFailure';    const DEFAULT_VALUE     = 'default';    const MESSAGES          = 'messages';    const ESCAPE_FILTER     = 'escapeFilter';    const FIELDS            = 'fields';    const FILTER            = 'filter';    const FILTER_CHAIN      = 'filterChain';    const MISSING_MESSAGE   = 'missingMessage';    const INPUT_NAMESPACE   = 'inputNamespace';    const NOT_EMPTY_MESSAGE = 'notEmptyMessage';    const PRESENCE          = 'presence';    const PRESENCE_OPTIONAL = 'optional';    const PRESENCE_REQUIRED = 'required';    const RULE              = 'rule';    const RULE_WILDCARD     = '*';    const VALIDATE          = 'validate';    const VALIDATOR         = 'validator';    const VALIDATOR_CHAIN   = 'validatorChain';    const VALIDATOR_CHAIN_COUNT = 'validatorChainCount';    /**     * @var array Input data, before processing.     */    protected $_data = array();    /**     * @var array Association of rules to filters.     */    protected $_filterRules = array();    /**     * @var array Association of rules to validators.     */    protected $_validatorRules = array();    /**     * @var array After processing data, this contains mapping of valid fields     * to field values.     */    protected $_validFields = array();    /**     * @var array After processing data, this contains mapping of validation     * rules that did not pass validation to the array of messages returned     * by the validator chain.     */    protected $_invalidMessages = array();    /**     * @var array After processing data, this contains mapping of validation     * rules that did not pass validation to the array of error identifiers     * returned by the validator chain.     */    protected $_invalidErrors = array();    /**     * @var array After processing data, this contains mapping of validation     * rules in which some fields were missing to the array of messages     * indicating which fields were missing.     */    protected $_missingFields = array();    /**     * @var array After processing, this contains a copy of $_data elements     * that were not mentioned in any validation rule.     */    protected $_unknownFields = array();    /**     * @var Zend_Filter_Interface The filter object that is run on values     * returned by the getEscaped() method.     */    protected $_defaultEscapeFilter = null;    /**     * Plugin loaders     * @var array     */    protected $_loaders = array();    /**     * @var array Default values to use when processing filters and validators.     */    protected $_defaults = array(        self::ALLOW_EMPTY         => false,        self::BREAK_CHAIN         => false,        self::ESCAPE_FILTER       => 'HtmlEntities',        self::MISSING_MESSAGE     => "Field '%field%' is required by rule '%rule%', but the field is missing",        self::NOT_EMPTY_MESSAGE   => "You must give a non-empty value for field '%field%'",        self::PRESENCE            => self::PRESENCE_OPTIONAL    );    /**     * @var boolean Set to False initially, this is set to True after the     * input data have been processed.  Reset to False in setData() method.     */    protected $_processed = false;    /**     * @param array $filterRules     * @param array $validatorRules     * @param array $data       OPTIONAL     * @param array $options    OPTIONAL     */    public function __construct($filterRules, $validatorRules, array $data = null, array $options = null)    {        if ($options) {            $this->setOptions($options);        }        $this->_filterRules = (array) $filterRules;        $this->_validatorRules = (array) $validatorRules;        if ($data) {            $this->setData($data);        }    }    /**     * @param mixed $namespaces     * @return Zend_Filter_Input     * @deprecated since 1.5.0RC1 - use addFilterPrefixPath() or addValidatorPrefixPath instead.     */    public function addNamespace($namespaces)    {        if (!is_array($namespaces)) {            $namespaces = array($namespaces);        }        foreach ($namespaces as $namespace) {            $prefix = $namespace;            $path = str_replace('_', DIRECTORY_SEPARATOR, $prefix);            $this->addFilterPrefixPath($prefix, $path);            $this->addValidatorPrefixPath($prefix, $path);        }        return $this;    }    /**     * Add prefix path for all elements     *     * @param  string $prefix     * @param  string $path     * @return Zend_Filter_Input     */    public function addFilterPrefixPath($prefix, $path)    {        $this->getPluginLoader(self::FILTER)->addPrefixPath($prefix, $path);        return $this;    }    /**     * Add prefix path for all elements     *     * @param  string $prefix     * @param  string $path     * @return Zend_Filter_Input     */    public function addValidatorPrefixPath($prefix, $path)    {        $this->getPluginLoader(self::VALIDATE)->addPrefixPath($prefix, $path);        return $this;    }    /**     * Set plugin loaders for use with decorators and elements     *     * @param  Zend_Loader_PluginLoader_Interface $loader     * @param  string $type 'filter' or 'validate'     * @return Zend_Filter_Input     * @throws Zend_Filter_Exception on invalid type     */    public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader, $type)    {        $type = strtolower($type);        switch ($type) {            case self::FILTER:            case self::VALIDATE:                $this->_loaders[$type] = $loader;                return $this;            default:                require_once 'Zend/Filter/Exception.php';                throw new Zend_Filter_Exception(sprintf('Invalid type "%s" provided to setPluginLoader()', $type));        }        return $this;    }    /**     * Retrieve plugin loader for given type     *     * $type may be one of:     * - filter     * - validator     *     * If a plugin loader does not exist for the given type, defaults are     * created.     *     * @param  string $type 'filter' or 'validate'     * @return Zend_Loader_PluginLoader_Interface     * @throws Zend_Filter_Exception on invalid type     */    public function getPluginLoader($type)    {        $type = strtolower($type);        if (!isset($this->_loaders[$type])) {            switch ($type) {                case self::FILTER:                    $prefixSegment = 'Zend_Filter_';                    $pathSegment   = 'Zend/Filter/';                    break;                case self::VALIDATE:                    $prefixSegment = 'Zend_Validate_';                    $pathSegment   = 'Zend/Validate/';                    break;                default:                    require_once 'Zend/Filter/Exception.php';                    throw new Zend_Filter_Exception(sprintf('Invalid type "%s" provided to getPluginLoader()', $type));            }            require_once 'Zend/Loader/PluginLoader.php';            $this->_loaders[$type] = new Zend_Loader_PluginLoader(                array($prefixSegment => $pathSegment)            );        }        return $this->_loaders[$type];    }    /**     * @return array     */    public function getMessages()    {        $this->_process();        return array_merge($this->_invalidMessages, $this->_missingFields);    }    /**     * @return array     */    public function getErrors()    {        $this->_process();        return $this->_invalidErrors;    }    /**     * @return array     */    public function getInvalid()    {        $this->_process();        return $this->_invalidMessages;    }    /**     * @return array     */    public function getMissing()    {        $this->_process();        return $this->_missingFields;    }    /**     * @return array     */    public function getUnknown()    {        $this->_process();        return $this->_unknownFields;    }    /**     * @param string $fieldName OPTIONAL     * @return mixed     */    public function getEscaped($fieldName = null)    {        $this->_process();        $this->_getDefaultEscapeFilter();        if ($fieldName === null) {            return $this->_escapeRecursive($this->_validFields);        }        if (array_key_exists($fieldName, $this->_validFields)) {            return $this->_escapeRecursive($this->_validFields[$fieldName]);        }        return null;    }    /**     * @param mixed $value     * @return mixed     */    protected function _escapeRecursive($data)    {        if (!is_array($data)) {            return $this->_getDefaultEscapeFilter()->filter($data);        }        foreach ($data as &$element) {            $element = $this->_escapeRecursive($element);        }        return $data;    }    /**     * @param string $fieldName OPTIONAL     * @return mixed     */    public function getUnescaped($fieldName = null)    {        $this->_process();        if ($fieldName === null) {            return $this->_validFields;        }        if (array_key_exists($fieldName, $this->_validFields)) {            return $this->_validFields[$fieldName];        }        return null;    }    /**     * @param string $fieldName     * @return mixed     */    public function __get($fieldName)    {        return $this->getEscaped($fieldName);    }    /**     * @return boolean     */    public function hasInvalid()    {        $this->_process();        return !(empty($this->_invalidMessages));    }    /**     * @return boolean     */    public function hasMissing()    {        $this->_process();        return !(empty($this->_missingFields));    }    /**     * @return boolean     */    public function hasUnknown()    {        $this->_process();        return !(empty($this->_unknownFields));    }    /**     * @return boolean     */    public function hasValid()    {        $this->_process();        return !(empty($this->_validFields));    }    /**     * @param string $fieldName     * @return boolean     */    public function isValid($fieldName = null)    {        $this->_process();        if ($fieldName === null) {            return !($this->hasMissing() || $this->hasInvalid());        }        return array_key_exists($fieldName, $this->_validFields);    }    /**     * @param string $fieldName     * @return boolean     */    public function __isset($fieldName)    {        $this->_process();        return isset($this->_validFields[$fieldName]);    }    /**     * @return Zend_Filter_Input     * @throws Zend_Filter_Exception     */    public function process()    {        $this->_process();        if ($this->hasInvalid()) {            require_once 'Zend/Filter/Exception.php';            throw new Zend_Filter_Exception("Input has invalid fields");        }        if ($this->hasMissing()) {            require_once 'Zend/Filter/Exception.php';            throw new Zend_Filter_Exception("Input has missing fields");        }        return $this;    }    /**     * @param array $data     * @return Zend_Filter_Input     */

⌨️ 快捷键说明

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