【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了InputFilter.php提供大家参考,希望对大家有所帮助!
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to version 1.0 of the Zend Framework
* license, that is bundled with this package in the file LICENSE,
* and is available through the world-wide-web at the following URL:
* http://www.zend.com/license/framework/1_0.txt. If you did not
* receive a copy of the Zend Framework license and are unable to
* obtain it through the world-wide-
web, please send a note to
* license@zend.com so we can mail you a copy immediately.
*
* @package Zend_InputFilter
* @copyright Copyright (c) 2006 Zend Technologies USA Inc.
* (http://www.zend.com/)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework
* License version 1.0
*/
/**
* Zend_InputFilter_Exception
*/
require_once 'Zend/InputFilter/Exception.php';
/**
* Zend_Filter
*/
require_once 'Zend/Filter.php';
/**
* @package Zend_InputFilter
* @copyright Copyright (c) 2006 Zend Technologies USA Inc.
* (http://www.zend.com/)
* @license http://www.zend.com/license/framework/1_0.txt Zend Framework
* License version 1.0
*/
class Zend_InputFilter
{
protected $_source = NULL;
public function __construct(&$source = NULL, $strict = TRUE)
{
$this->_source = $source;
if ($strict) {
$source = NULL;
}
}
/**
* Returns only the alphabetic characters in value.
*
* @param mixed $key
* @return mixed
*/
public function getAlpha($key)
{
return Zend_Filter::getAlpha($this->_source[$key]);
}
/**
* Returns only the alphabetic characters and digits in value.
*
* @param mixed $key
* @return mixed
*/
public function getAlnum($key)
{
return Zend_Filter::getAlnum($this->_source[$key]);
}
/**
* Returns only the digits in value. This differs from getInt().
*
* @param mixed $key
* @return mixed
*/
public function getDigits($key)
{
return Zend_Filter::getDigits($this->_source[$key]);
}
/**
* Returns dirname(value).
*
* @param mixed $key
* @return mixed
*/
public function getDir($key)
{
return Zend_Filter::getDir($this->_source[$key]);
}
/**
* Returns (int) value.
*
* @param mixed $key
* @return int
*/
public function getInt($key)
{
return Zend_Filter::getInt($this->_source[$key]);
}
/**
* Returns realpath(value).
*
* @param mixed $key
* @return mixed
*/
public function getPath($key)
{
return Zend_Filter::getPath($this->_source[$key]);
}
/**
* Returns value.
*
* @param string $key
* @return mixed
*/
public function getRaw($key)
{
return $this->_source[$key];
}
/**
* Returns value if every character is alphabetic or a digit,
* FALSE otherwise.
*
* @param mixed $key
* @return mixed
*/
public function testAlnum($key)
{
if (Zend_Filter::isAlnum($this->_source[$key])) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns value if every character is alphabetic, FALSE
* otherwise.
*
* @param mixed $key
* @return mixed
*/
public function testAlpha($key)
{
if (Zend_Filter::isAlpha($this->_source[$key])) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns value if it is greater than or equal to $min and less
* than or equal to $max, FALSE otherwise. If $inc is set to
* FALSE, then the value must be strictly greater than $min and
* strictly less than $max.
*
* @param mixed $key
* @param mixed $min
* @param mixed $max
* @param boolean $inclusive
* @return mixed
*/
public function testBetween($key, $min, $max, $inc = TRUE)
{
if (Zend_Filter::isBetween($this->_source[$key], $min, $max, $inc)) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns value if it is a valid credit card number format. The
* optional second argument allows developers to indicate the
* type.
*
* @param mixed $key
* @param mixed $type
* @return mixed
*/
public function testCcnum($key, $type = NULL)
{
if (Zend_Filter::isCcnum($this->_source[$key], $type)) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns $value if it is a valid date, FALSE otherwise. The
* date is required to be in ISO 8601 format.
*
* @param mixed $key
* @return mixed
*/
public function testDate($key)
{
if (Zend_Filter::isDate($this->_source[$key])) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns value if every character is a digit, FALSE otherwise.
* This is just like isInt(), except there is no upper limit.
*
* @param mixed $key
* @return mixed
*/
public function testDigits($key)
{
if (Zend_Filter::isDigits($this->_source[$key])) {
return $this->_source[$key];
}
return FALSE;
}
/**
* Returns value if it is a valid email format, FALSE otherwise.
*
* @param mixed $key
* @return mixed
*/
public function te