import v2.0.0.0_RC3 | 2012-07-01
https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 16223 2009-06-21 20:04:53Z thomas $
|
||||
* @version $Id: Abstract.php 18688 2009-10-25 16:08:24Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -142,12 +142,17 @@ abstract class Zend_Validate_Abstract implements Zend_Validate_Interface
|
||||
{
|
||||
if ($messageKey === null) {
|
||||
$keys = array_keys($this->_messageTemplates);
|
||||
$messageKey = current($keys);
|
||||
foreach($keys as $key) {
|
||||
$this->setMessage($messageString, $key);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!isset($this->_messageTemplates[$messageKey])) {
|
||||
require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
|
||||
}
|
||||
|
||||
$this->_messageTemplates[$messageKey] = $messageString;
|
||||
return $this;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
@ -17,104 +17,104 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Abstract.php 17160 2009-07-26 19:46:24Z bittarman $
|
||||
*/
|
||||
|
||||
* @version $Id: Abstract.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Abstract
|
||||
*/
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
*/
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
|
||||
/**
|
||||
* Class for Database record validation
|
||||
*
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @uses Zend_Validate_Abstract
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
|
||||
{
|
||||
*/
|
||||
abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* Error constants
|
||||
*/
|
||||
const ERROR_NO_RECORD_FOUND = 'noRecordFound';
|
||||
const ERROR_RECORD_FOUND = 'recordFound';
|
||||
|
||||
*/
|
||||
const ERROR_NO_RECORD_FOUND = 'noRecordFound';
|
||||
const ERROR_RECORD_FOUND = 'recordFound';
|
||||
|
||||
/**
|
||||
* @var array Message templates
|
||||
*/
|
||||
protected $_messageTemplates = array(self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found',
|
||||
self::ERROR_RECORD_FOUND => 'A record matching %value% was found');
|
||||
*/
|
||||
protected $_messageTemplates = array(self::ERROR_NO_RECORD_FOUND => 'No record matching %value% was found',
|
||||
self::ERROR_RECORD_FOUND => 'A record matching %value% was found');
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
*/
|
||||
protected $_schema = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_table = '';
|
||||
|
||||
*/
|
||||
protected $_table = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_field = '';
|
||||
|
||||
*/
|
||||
protected $_field = '';
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_exclude = null;
|
||||
|
||||
*/
|
||||
protected $_exclude = null;
|
||||
|
||||
/**
|
||||
* Database adapter to use. If null isValid() will use Zend_Db::getInstance instead
|
||||
*
|
||||
* @var unknown_type
|
||||
*/
|
||||
protected $_adapter = null;
|
||||
|
||||
*/
|
||||
protected $_adapter = null;
|
||||
|
||||
/**
|
||||
* Provides basic configuration for use with Zend_Validate_Db Validators
|
||||
* Provides basic configuration for use with Zend_Validate_Db Validators
|
||||
* Setting $exclude allows a single record to be excluded from matching.
|
||||
* Exclude can either be a String containing a where clause, or an array with `field` and `value` keys
|
||||
* to define the where clause added to the sql.
|
||||
* A database adapter may optionally be supplied to avoid using the registered default adapter.
|
||||
*
|
||||
* to define the where clause added to the sql.
|
||||
* A database adapter may optionally be supplied to avoid using the registered default adapter.
|
||||
*
|
||||
* @param string||array $table The database table to validate against, or array with table and schema keys
|
||||
* @param string $field The field to check for a match
|
||||
* @param string||array $exclude An optional where clause or field/value pair to exclude from the query
|
||||
* @param Zend_Db_Adapter_Abstract $adapter An optional database adapter to use.
|
||||
*/
|
||||
public function __construct($table, $field, $exclude = null, Zend_Db_Adapter_Abstract $adapter = null)
|
||||
{
|
||||
if ($adapter !== null) {
|
||||
$this->_adapter = $adapter;
|
||||
}
|
||||
$this->_exclude = $exclude;
|
||||
$this->_field = (string) $field;
|
||||
|
||||
*/
|
||||
public function __construct($table, $field, $exclude = null, Zend_Db_Adapter_Abstract $adapter = null)
|
||||
{
|
||||
if ($adapter !== null) {
|
||||
$this->_adapter = $adapter;
|
||||
}
|
||||
$this->_exclude = $exclude;
|
||||
$this->_field = (string) $field;
|
||||
|
||||
if (is_array($table)) {
|
||||
$this->_table = (isset($table['table'])) ? $table['table'] : '';
|
||||
$this->_schema = (isset($table['schema'])) ? $table['schema'] : null;
|
||||
$this->_schema = (isset($table['schema'])) ? $table['schema'] : null;
|
||||
} else {
|
||||
$this->_table = (string) $table;
|
||||
$this->_table = (string) $table;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Run query and returns matches, or null if no matches are found.
|
||||
*
|
||||
* @param String $value
|
||||
* @return Array when matches are found.
|
||||
*/
|
||||
protected function _query($value)
|
||||
{
|
||||
*/
|
||||
protected function _query($value)
|
||||
{
|
||||
/**
|
||||
* Check for an adapter being defined. if not, fetch the default adapter.
|
||||
*/
|
||||
*/
|
||||
if ($this->_adapter === null) {
|
||||
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
|
||||
if (null === $this->_adapter) {
|
||||
@ -125,24 +125,24 @@ abstract class Zend_Validate_Db_Abstract extends Zend_Validate_Abstract
|
||||
|
||||
/**
|
||||
* Build select object
|
||||
*/
|
||||
*/
|
||||
$select = new Zend_Db_Select($this->_adapter);
|
||||
$select->from($this->_table, array($this->_field), $this->_schema)
|
||||
->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value);
|
||||
if ($this->_exclude !== null) {
|
||||
if (is_array($this->_exclude)) {
|
||||
$select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).' != ?', $this->_exclude['value']);
|
||||
} else {
|
||||
$select->where($this->_exclude);
|
||||
}
|
||||
}
|
||||
$select->limit(1);
|
||||
|
||||
->where($this->_adapter->quoteIdentifier($this->_field).' = ?', $value);
|
||||
if ($this->_exclude !== null) {
|
||||
if (is_array($this->_exclude)) {
|
||||
$select->where($this->_adapter->quoteIdentifier($this->_exclude['field']).' != ?', $this->_exclude['value']);
|
||||
} else {
|
||||
$select->where($this->_exclude);
|
||||
}
|
||||
}
|
||||
$select->limit(1);
|
||||
|
||||
/**
|
||||
* Run query
|
||||
*/
|
||||
$result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC);
|
||||
|
||||
return $result;
|
||||
}
|
||||
*/
|
||||
$result = $this->_adapter->fetchRow($select, array(), Zend_Db::FETCH_ASSOC);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
@ -17,37 +17,37 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: RecordExists.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
*/
|
||||
|
||||
|
||||
* @version $Id: RecordExists.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Db_Abstract
|
||||
*/
|
||||
require_once 'Zend/Validate/Db/Abstract.php';
|
||||
|
||||
*/
|
||||
require_once 'Zend/Validate/Db/Abstract.php';
|
||||
|
||||
/**
|
||||
* Confirms a record exists in a table.
|
||||
*
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Validate
|
||||
* @uses Zend_Validate_Db_Abstract
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Validate_Db_RecordExists extends Zend_Validate_Db_Abstract
|
||||
{
|
||||
public function isValid($value)
|
||||
{
|
||||
$valid = true;
|
||||
$this->_setValue($value);
|
||||
|
||||
$result = $this->_query($value);
|
||||
if (!$result) {
|
||||
$valid = false;
|
||||
$this->_error(self::ERROR_NO_RECORD_FOUND);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
*/
|
||||
class Zend_Validate_Db_RecordExists extends Zend_Validate_Db_Abstract
|
||||
{
|
||||
public function isValid($value)
|
||||
{
|
||||
$valid = true;
|
||||
$this->_setValue($value);
|
||||
|
||||
$result = $this->_query($value);
|
||||
if (!$result) {
|
||||
$valid = false;
|
||||
$this->_error(self::ERROR_NO_RECORD_FOUND);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Count.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Count.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -100,8 +100,7 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract
|
||||
* 'min': Minimum filecount
|
||||
* 'max': Maximum filecount
|
||||
*
|
||||
* @param integer|array $options Options for the adapter
|
||||
* @param integer $max (Deprecated) Maximum value (implies $options is the minimum)
|
||||
* @param integer|array|Zend_Config $options Options for the adapter
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
@ -116,7 +115,8 @@ class Zend_Validate_File_Count extends Zend_Validate_Abstract
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
trigger_error('Multiple arguments are deprecated in favor of an array of named arguments', E_USER_NOTICE);
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple arguments are deprecated in favor of an array of named arguments', E_USER_NOTICE);
|
||||
$options['min'] = func_get_arg(0);
|
||||
$options['max'] = func_get_arg(1);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Crc32.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Crc32.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -60,7 +60,7 @@ class Zend_Validate_File_Crc32 extends Zend_Validate_File_Hash
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $options
|
||||
* @param string|array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ExcludeMimeType.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: ExcludeMimeType.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -51,20 +51,38 @@ class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
if ($file === null) {
|
||||
$file = array(
|
||||
'type' => null,
|
||||
'name' => $value
|
||||
);
|
||||
}
|
||||
|
||||
// Is file readable ?
|
||||
require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
if (class_exists('finfo', false) && defined('MAGIC')) {
|
||||
$mime = new finfo(FILEINFO_MIME);
|
||||
$this->_type = $mime->file($value);
|
||||
unset($mime);
|
||||
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
$mimefile = $this->getMagicFile();
|
||||
if (class_exists('finfo', false)) {
|
||||
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
|
||||
if (!empty($mimefile)) {
|
||||
$mime = new finfo($const, $mimefile);
|
||||
} else {
|
||||
$mime = new finfo($const);
|
||||
}
|
||||
|
||||
if ($mime !== false) {
|
||||
$this->_type = $mime->file($value);
|
||||
}
|
||||
unset($mime);
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} elseif ($this->_headerCheck) {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Exists.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Exists.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -62,7 +62,7 @@ class Zend_Validate_File_Exists extends Zend_Validate_Abstract
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $directory
|
||||
* @param string|array|Zend_Config $directory
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($directory = array())
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Extension.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Extension.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -71,8 +71,7 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $extension
|
||||
* @param boolean $case If true validation is done case sensitive
|
||||
* @param string|array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
@ -82,7 +81,8 @@ class Zend_Validate_File_Extension extends Zend_Validate_Abstract
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
trigger_error('Multiple arguments to constructor are deprecated in favor of options array', E_USER_NOTICE);
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple arguments to constructor are deprecated in favor of options array', E_USER_NOTICE);
|
||||
$case = func_get_arg(1);
|
||||
$this->setCase($case);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: FilesSize.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: FilesSize.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -63,9 +63,7 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
|
||||
* Min limits the used diskspace for all files, when used with max=null it is the maximum filesize
|
||||
* It also accepts an array with the keys 'min' and 'max'
|
||||
*
|
||||
* @param integer|array $min Minimum diskspace for all files
|
||||
* @param integer $max Maximum diskspace for all files (deprecated)
|
||||
* @param boolean $bytestring Use bytestring or real size ? (deprecated)
|
||||
* @param integer|array|Zend_Config $options Options for this validator
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
@ -73,16 +71,18 @@ class Zend_Validate_File_FilesSize extends Zend_Validate_File_Size
|
||||
$this->_files = array();
|
||||
$this->_setSize(0);
|
||||
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_scalar($options)) {
|
||||
$options = array('max' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid options to validator provided');
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (is_scalar($options)) {
|
||||
$options = array('min' => $options);
|
||||
} elseif (!is_array($options)) {
|
||||
require_once 'Zend/Validate/Exception.php';
|
||||
throw new Zend_Validate_Exception('Invalid options to validator provided');
|
||||
}
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
|
||||
$argv = func_get_args();
|
||||
array_shift($argv);
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Hash.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Hash.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -75,7 +75,8 @@ class Zend_Validate_File_Hash extends Zend_Validate_Abstract
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
$options['algorithm'] = func_get_arg(1);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: ImageSize.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: ImageSize.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -124,15 +124,11 @@ class Zend_Validate_File_ImageSize extends Zend_Validate_Abstract
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$minwidth = 0;
|
||||
$minheight = 0;
|
||||
$maxwidth = null;
|
||||
$maxheight = null;
|
||||
|
||||
if ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (1 < func_num_args()) {
|
||||
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
if (!is_array($options)) {
|
||||
$options = array('minwidth' => $options);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: IsCompressed.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: IsCompressed.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -53,12 +53,14 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $compression
|
||||
* @param string|array|Zend_Config $compression
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($mimetype = array())
|
||||
{
|
||||
if (empty($mimetype)) {
|
||||
if ($mimetype instanceof Zend_Config) {
|
||||
$mimetype = $mimetype->toArray();
|
||||
} else if (empty($mimetype)) {
|
||||
$mimetype = array(
|
||||
'application/x-tar',
|
||||
'application/x-cpio',
|
||||
@ -81,53 +83,4 @@ class Zend_Validate_File_IsCompressed extends Zend_Validate_File_MimeType
|
||||
|
||||
$this->setMimeType($mimetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the file is compression with the set compression types
|
||||
*
|
||||
* @param string $value Real file to check for compression
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
if (class_exists('finfo', false) && defined('MAGIC')) {
|
||||
$mime = new finfo(FILEINFO_MIME);
|
||||
$this->_type = $mime->file($value);
|
||||
unset($mime);
|
||||
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} else {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
$compressions = $this->getMimeType(true);
|
||||
if (in_array($this->_type, $compressions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$types = explode('/', $this->_type);
|
||||
$types = array_merge($types, explode('-', $this->_type));
|
||||
foreach ($compressions as $mime) {
|
||||
if (in_array($mime, $types)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::FALSE_TYPE);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: IsImage.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: IsImage.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -53,12 +53,14 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
* @param string|array $mimetype
|
||||
* @param string|array|Zend_Config $mimetype
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($mimetype = array())
|
||||
{
|
||||
if (empty($mimetype)) {
|
||||
if ($mimetype instanceof Zend_Config) {
|
||||
$mimetype = $mimetype->toArray();
|
||||
} else if (empty($mimetype)) {
|
||||
$mimetype = array(
|
||||
'image/x-quicktime',
|
||||
'image/jp2',
|
||||
@ -85,53 +87,4 @@ class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType
|
||||
|
||||
$this->setMimeType($mimetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Validate_Interface
|
||||
*
|
||||
* Returns true if and only if the file is compression with the set compression types
|
||||
*
|
||||
* @param string $value Real file to check for compression
|
||||
* @param array $file File data from Zend_File_Transfer
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
// Is file readable ?
|
||||
require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
if (class_exists('finfo', false) && defined('MAGIC')) {
|
||||
$mime = new finfo(FILEINFO_MIME);
|
||||
$this->_type = $mime->file($value);
|
||||
unset($mime);
|
||||
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} else {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
return $this->_throw($file, self::NOT_DETECTED);
|
||||
}
|
||||
|
||||
$compressions = $this->getMimeType(true);
|
||||
if (in_array($this->_type, $compressions)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$types = explode('/', $this->_type);
|
||||
$types = array_merge($types, explode('-', $this->_type));
|
||||
foreach($compressions as $mime) {
|
||||
if (in_array($mime, $types)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_throw($file, self::FALSE_TYPE);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: MimeType.php 17203 2009-07-27 19:37:18Z thomas $
|
||||
* @version $Id: MimeType.php 18513 2009-10-12 16:17:35Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -79,6 +79,29 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
|
||||
*/
|
||||
protected $_magicfile;
|
||||
|
||||
/**
|
||||
* If no $_ENV['MAGIC'] is set, try and autodiscover it based on common locations
|
||||
* @var array
|
||||
*/
|
||||
protected $_magicFiles = array(
|
||||
'/usr/share/misc/magic',
|
||||
'/usr/share/misc/magic.mime',
|
||||
'/usr/share/misc/magic.mgc',
|
||||
'/usr/share/mime/magic',
|
||||
'/usr/share/mime/magic.mime',
|
||||
'/usr/share/mime/magic.mgc',
|
||||
'/usr/share/file/magic',
|
||||
'/usr/share/file/magic.mime',
|
||||
'/usr/share/file/magic.mgc',
|
||||
);
|
||||
|
||||
/**
|
||||
* Option to allow header check
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_headerCheck = false;
|
||||
|
||||
/**
|
||||
* Sets validator options
|
||||
*
|
||||
@ -102,16 +125,28 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
|
||||
$this->setMagicFile($mimetype['magicfile']);
|
||||
}
|
||||
|
||||
if (isset($mimetype['headerCheck'])) {
|
||||
$this->enableHeaderCheck(true);
|
||||
}
|
||||
|
||||
$this->setMimeType($mimetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returna the actual set magicfile
|
||||
* Returns the actual set magicfile
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMagicFile()
|
||||
{
|
||||
if (null === $this->_magicfile && empty($_ENV['MAGIC'])) {
|
||||
foreach ($this->_magicFiles as $file) {
|
||||
if (file_exists($file)) {
|
||||
$this->setMagicFile($file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_magicfile;
|
||||
}
|
||||
|
||||
@ -136,6 +171,29 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Header Check option
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getHeaderCheck()
|
||||
{
|
||||
return $this->_headerCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if the http header should be used
|
||||
* Note that this is unsave and therefor the default value is false
|
||||
*
|
||||
* @param boolean $checkHeader
|
||||
* @return Zend_Validate_File_MimeType Provides fluid interface
|
||||
*/
|
||||
public function enableHeaderCheck($headerCheck = true)
|
||||
{
|
||||
$this->_headerCheck = (boolean) $headerCheck;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set mimetypes
|
||||
*
|
||||
@ -220,35 +278,39 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
|
||||
*/
|
||||
public function isValid($value, $file = null)
|
||||
{
|
||||
if ($file === null) {
|
||||
$file = array(
|
||||
'type' => null,
|
||||
'name' => $value
|
||||
);
|
||||
}
|
||||
|
||||
// Is file readable ?
|
||||
require_once 'Zend/Loader.php';
|
||||
if (!Zend_Loader::isReadable($value)) {
|
||||
return $this->_throw($file, self::NOT_READABLE);
|
||||
}
|
||||
|
||||
if ($file !== null) {
|
||||
$mimefile = $this->getMagicFile();
|
||||
if (class_exists('finfo', false)) {
|
||||
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
|
||||
if (!empty($mimefile)) {
|
||||
$mime = new finfo($const, $mimefile);
|
||||
} else {
|
||||
$mime = new finfo($const);
|
||||
}
|
||||
|
||||
if ($mime !== false) {
|
||||
$this->_type = $mime->file($value);
|
||||
}
|
||||
|
||||
unset($mime);
|
||||
$mimefile = $this->getMagicFile();
|
||||
if (class_exists('finfo', false)) {
|
||||
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
|
||||
if (!empty($mimefile)) {
|
||||
$mime = new finfo($const, $mimefile);
|
||||
} else {
|
||||
$mime = new finfo($const);
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} else {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
if ($mime !== false) {
|
||||
$this->_type = $mime->file($value);
|
||||
}
|
||||
unset($mime);
|
||||
}
|
||||
|
||||
if (empty($this->_type)) {
|
||||
if (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
|
||||
$this->_type = mime_content_type($value);
|
||||
} elseif ($this->_headerCheck) {
|
||||
$this->_type = $file['type'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,10 +343,7 @@ class Zend_Validate_File_MimeType extends Zend_Validate_Abstract
|
||||
*/
|
||||
protected function _throw($file, $errorType)
|
||||
{
|
||||
if ($file !== null) {
|
||||
$this->_value = $file['name'];
|
||||
}
|
||||
|
||||
$this->_value = $file['name'];
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Size.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Size.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -112,7 +112,8 @@ class Zend_Validate_File_Size extends Zend_Validate_Abstract
|
||||
}
|
||||
|
||||
if (1 < func_num_args()) {
|
||||
trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
// @todo: Preperation for 2.0... needs to be cleared with the dev-team
|
||||
// trigger_error('Multiple constructor options are deprecated in favor of a single options array', E_USER_NOTICE);
|
||||
$argv = func_get_args();
|
||||
array_shift($argv);
|
||||
$options['max'] = array_shift($argv);
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Upload.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Upload.php 18148 2009-09-16 19:27:43Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -78,11 +78,15 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
|
||||
* If no files are given the $_FILES array will be used automatically.
|
||||
* NOTE: This validator will only work with HTTP POST uploads!
|
||||
*
|
||||
* @param array $files Array of files in syntax of Zend_File_Transfer
|
||||
* @param array|Zend_Config $files Array of files in syntax of Zend_File_Transfer
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($files = array())
|
||||
{
|
||||
if ($files instanceof Zend_Config) {
|
||||
$files = $files->toArray();
|
||||
}
|
||||
|
||||
$this->setFiles($files);
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
* @package Zend_Validate
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: NotEmpty.php 17680 2009-08-19 20:02:26Z thomas $
|
||||
* @version $Id: NotEmpty.php 18186 2009-09-17 18:57:00Z matthew $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -53,8 +53,8 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract
|
||||
*/
|
||||
public function isValid($value)
|
||||
{
|
||||
if (!is_string($value) && !is_int($value) && !is_float($value) && !is_bool($value) &&
|
||||
!is_array($value)) {
|
||||
if (!is_null($value) && !is_string($value) && !is_int($value) && !is_float($value) &&
|
||||
!is_bool($value) && !is_array($value)) {
|
||||
$this->_error(self::INVALID);
|
||||
return false;
|
||||
}
|
||||
@ -66,6 +66,8 @@ class Zend_Validate_NotEmpty extends Zend_Validate_Abstract
|
||||
) {
|
||||
$this->_error(self::IS_EMPTY);
|
||||
return false;
|
||||
} elseif (is_int($value) && (0 === $value)) {
|
||||
return true;
|
||||
} elseif (!is_string($value) && empty($value)) {
|
||||
$this->_error(self::IS_EMPTY);
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user