Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 45 changed files with 486 additions and 72 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function setOptions($options = array())
} elseif (isset($this->options)) {
$this->options[$name] = $option;
} else {
$this->abstractOptions[$name] = $options;
$this->abstractOptions[$name] = $option;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Barcode/Code128.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Code128 extends AbstractAdapter
/**
* The used string wrapper used for basic UTF-8 string functions
*
* @var SrtringWrapperInterface
* @var StringWrapperInterface
*/
protected $utf8StringWrapper;

Expand Down
2 changes: 1 addition & 1 deletion src/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CreditCard extends AbstractValidator
self::INVALID => "Invalid type given. String expected",
self::LENGTH => "The input contains an invalid amount of digits",
self::PREFIX => "The input is not from an allowed institute",
self::SERVICE => "The input seems to be an invalid creditcard number",
self::SERVICE => "The input seems to be an invalid credit card number",
self::SERVICEFAILURE => "An exception has been raised while validating the input",
);

Expand Down
1 change: 1 addition & 0 deletions src/Csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public function setSession(SessionContainer $session)
public function getSession()
{
if (null === $this->session) {
// Using fully qualified name, to ensure polyfill class alias is used
$this->session = new SessionContainer($this->getSessionName());
}
return $this->session;
Expand Down
2 changes: 1 addition & 1 deletion src/Explode.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Explode extends AbstractValidator
* @var array
*/
protected $messageTemplates = array(
self::INVALID => "Invalid type given.",
self::INVALID => "Invalid type given",
);

/**
Expand Down
3 changes: 0 additions & 3 deletions src/File/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Validator
*/

namespace Zend\Validator\File;
Expand All @@ -16,8 +15,6 @@
/**
* Validator for counting all given files
*
* @category Zend
* @package Zend_Validator
*/
class Count extends AbstractValidator
{
Expand Down
9 changes: 7 additions & 2 deletions src/File/Crc32.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ public function addCrc32($options)
* Returns true if and only if the given file confirms the set hash
*
* @param string|array $value Filename to check for hash
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
9 changes: 7 additions & 2 deletions src/File/ExcludeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ class ExcludeExtension extends Extension
* set extension list
*
* @param string|array $value Real file to check for extension
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
15 changes: 10 additions & 5 deletions src/File/ExcludeMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ class ExcludeMimeType extends MimeType
* mime types will not be accepted like "image/gif", "image/jpeg" and so on.
*
* @param string|array $value Real file to check for mimetype
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name']) || !isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand All @@ -55,13 +61,12 @@ public function isValid($value)

$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
$this->finfo = finfo_open($const, $mimefile);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
}

if (empty($this->finfo)) {
$this->finfo = finfo_open($const);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE);
}

$this->type = null;
Expand Down
10 changes: 8 additions & 2 deletions src/File/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ public function addDirectory($directory)
* Returns true if and only if the file already exists in the set directories
*
* @param string|array $value Real file to check for existence
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
9 changes: 7 additions & 2 deletions src/File/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ public function addExtension($extension)
* set extension list
*
* @param string|array $value Real file to check for extension
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
3 changes: 0 additions & 3 deletions src/File/FilesSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Validator
*/

namespace Zend\Validator\File;
Expand All @@ -18,8 +17,6 @@
/**
* Validator for the size of all files which will be validated in sum
*
* @category Zend
* @package Zend_Validator
*/
class FilesSize extends Size
{
Expand Down
9 changes: 7 additions & 2 deletions src/File/Hash.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ public function addHash($options)
* Returns true if and only if the given file confirms the set hash
*
* @param string|array $value File to check for hash
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
9 changes: 7 additions & 2 deletions src/File/ImageSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,16 @@ public function setImageHeight($options)
* not bigger than max
*
* @param string|array $value Real file to check for image size
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
8 changes: 6 additions & 2 deletions src/File/IsCompressed.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,14 @@ public function __construct($options = array())
$options = ArrayUtils::iteratorToArray($options);
}

if (empty($options)) {
$options = array('mimeType' => $default);
if ($options === null) {
$options = array();
}

parent::__construct($options);

if (!$this->getMimeType()) {
$this->setMimeType($default);
}
}
}
8 changes: 6 additions & 2 deletions src/File/IsImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ public function __construct($options = array())
$options = ArrayUtils::iteratorToArray($options);
}

if (empty($options)) {
$options = array('mimeType' => $default);
if ($options === null) {
$options = array();
}

parent::__construct($options);

if (!$this->getMimeType()) {
$this->setMimeType($default);
}
}
}
11 changes: 8 additions & 3 deletions src/File/Md5.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Md5 extends Hash
*/
protected $messageTemplates = array(
self::DOES_NOT_MATCH => "File does not match the given md5 hashes",
self::NOT_DETECTED => "A md5 hash could not be evaluated for the given file",
self::NOT_DETECTED => "An md5 hash could not be evaluated for the given file",
self::NOT_FOUND => "File is not readable or does not exist",
);

Expand Down Expand Up @@ -80,11 +80,16 @@ public function addMd5($options)
* Returns true if and only if the given file confirms the set hash
*
* @param string|array $value Filename to check for hash
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
18 changes: 11 additions & 7 deletions src/File/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ public function setMagicFile($file)
$file
));
} else {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $file);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
$this->finfo = null;
Expand Down Expand Up @@ -342,11 +341,17 @@ public function addMimeType($mimetype)
* mime types will be accepted like "image/gif", "image/jpeg" and so on.
*
* @param string|array $value Real file to check for mimetype
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$filetype = $file['type'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name']) || !isset($value['type'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand All @@ -370,16 +375,15 @@ public function isValid($value)

$mimefile = $this->getMagicFile();
if (class_exists('finfo', false)) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
if (!$this->isMagicFileDisabled() && (!empty($mimefile) && empty($this->finfo))) {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const, $mimefile);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $mimefile);
ErrorHandler::stop();
}

if (empty($this->finfo)) {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open($const);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE);
ErrorHandler::stop();
}

Expand Down
10 changes: 8 additions & 2 deletions src/File/NotExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ class NotExists extends Exists
* Returns true if and only if the file does not exist in the set destinations
*
* @param string|array $value Real file to check for existence
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
$this->setValue($filename);
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
9 changes: 7 additions & 2 deletions src/File/Sha1.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,16 @@ public function addSha1($options)
* Returns true if and only if the given file confirms the set hash
*
* @param string $value|array Filename to check for hash
* @param array $file File data from \Zend\File\Transfer\Transfer (optional)
* @return bool
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (is_array($value)) {
if (is_string($value) && is_array($file)) {
// Legacy Zend\Transfer API support
$filename = $file['name'];
$file = $file['tmp_name'];
} elseif (is_array($value)) {
if (!isset($value['tmp_name']) || !isset($value['name'])) {
throw new Exception\InvalidArgumentException(
'Value array must be in $_FILES format'
Expand Down
Loading

0 comments on commit 6713bf5

Please sign in to comment.