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

Commit

Permalink
Merging develop to master in preparation for 2.12.0 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jan 30, 2019
2 parents 3c28dfe + 6c19585 commit 64c3366
Show file tree
Hide file tree
Showing 22 changed files with 633 additions and 273 deletions.
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sudo: false

language: php

branches:
Expand Down Expand Up @@ -59,6 +57,15 @@ matrix:
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=locked
- php: 7.3
env:
- DEPS=latest

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.12.0 - 2019-01-30

### Added

- [#250](https://github.com/zendframework/zend-validator/pull/250) adds support for PHP 7.3.

### Changed

- [#251](https://github.com/zendframework/zend-validator/pull/251) updates the logic of each of the various `Zend\Validator\File` validators
to allow validating against PSR-7 `UploadedFileInterface` instances, expanding
the support originally provided in version 2.11.0.

### Deprecated

- Nothing.

### Removed

- [#250](https://github.com/zendframework/zend-validator/pull/250) removes support for zend-stdlib v2 releases.

### Fixed

- Nothing.

## 2.11.1 - 2019-01-29

### Added
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-stdlib": "^2.7.6 || ^3.1",
"zendframework/zend-stdlib": "^3.2.1",
"container-interop/container-interop": "^1.1"
},
"require-dev": {
Expand Down Expand Up @@ -47,8 +47,8 @@
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "2.11.x-dev",
"dev-develop": "2.12.x-dev"
"dev-master": "2.12.x-dev",
"dev-develop": "2.13.x-dev"
},
"zf": {
"component": "Zend\\Validator",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/DateStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ protected function convertString($value, $addErrors = true)
if (strpos($this->format, 'Y-\WW') === 0
&& preg_match('/^([0-9]{4})\-W([0-9]{2})/', $value, $matches)
) {
$date = new DateTime;
$date = new DateTime();
$date->setISODate($matches[1], $matches[2]);
} else {
$date = DateTime::createFromFormat($this->format, $value, $this->timezone);
$date = DateTime::createFromFormat($this->format, $value, new DateTimeZone('UTC'));
}

// Invalid dates can show up as warnings (ie. "2007-02-99")
Expand Down
28 changes: 8 additions & 20 deletions src/File/Crc32.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

namespace Zend\Validator\File;

use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;

/**
* Validator for the crc32 hash of given files
*/
class Crc32 extends Hash
{
use FileInformationTrait;

/**
* @const string Error constants
*/
Expand Down Expand Up @@ -85,32 +87,18 @@ public function addCrc32($options)
*/
public function isValid($value, $file = null)
{
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'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);

$this->setValue($fileInfo['filename']);

// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}

$hashes = array_unique(array_keys($this->getHash()));
$filehash = hash_file('crc32', $file);
$filehash = hash_file('crc32', $fileInfo['file']);
if ($filehash === false) {
$this->error(self::NOT_DETECTED);
return false;
Expand Down
27 changes: 8 additions & 19 deletions src/File/ExcludeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

namespace Zend\Validator\File;

use Zend\Validator\File\FileInformationTrait;
use Zend\Validator\Exception;

/**
* Validator for the excluding file extensions
*/
class ExcludeExtension extends Extension
{
use FileInformationTrait;

/**
* @const string Error constants
*/
Expand All @@ -40,31 +43,17 @@ class ExcludeExtension extends Extension
*/
public function isValid($value, $file = null)
{
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'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);

$this->setValue($fileInfo['filename']);

// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}

$extension = substr($filename, strrpos($filename, '.') + 1);
$extension = substr($fileInfo['filename'], strrpos($fileInfo['filename'], '.') + 1);
$extensions = $this->getExtension();

if ($this->getCase() && (! in_array($extension, $extensions))) {
Expand Down
33 changes: 9 additions & 24 deletions src/File/ExcludeMimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
namespace Zend\Validator\File;

use finfo;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;

/**
* Validator for the mime type of a file
*/
class ExcludeMimeType extends MimeType
{
use FileInformationTrait;

const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
Expand All @@ -41,29 +43,12 @@ class ExcludeMimeType extends MimeType
*/
public function isValid($value, $file = null)
{
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'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
$filetype = $value['type'];
} else {
$file = $value;
$filename = basename($file);
$filetype = null;
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file, true);

$this->setValue($fileInfo['filename']);

// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_READABLE);
return false;
}
Expand All @@ -80,12 +65,12 @@ public function isValid($value, $file = null)

$this->type = null;
if (! empty($this->finfo)) {
$this->type = finfo_file($this->finfo, $file);
$this->type = finfo_file($this->finfo, $fileInfo['file']);
}
}

if (empty($this->type) && $this->getHeaderCheck()) {
$this->type = $filetype;
$this->type = $fileInfo['filetype'];
}

if (empty($this->type)) {
Expand Down
29 changes: 8 additions & 21 deletions src/File/Exists.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Zend\Validator\File\FileInformationTrait;

/**
* Validator which checks if the file already exists in the directory
*/
class Exists extends AbstractValidator
{
use FileInformationTrait;

/**
* @const string Error constants
*/
Expand Down Expand Up @@ -144,31 +147,15 @@ public function addDirectory($directory)
*/
public function isValid($value, $file = null)
{
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'
);
}
$file = $value['tmp_name'];
$filename = basename($file);
$this->setValue($value['name']);
} else {
$file = $value;
$filename = basename($file);
$this->setValue($filename);
}
$fileInfo = $this->getFileInfo($value, $file, false, true);

$this->setValue($fileInfo['filename']);

$check = false;
$directories = $this->getDirectory(true);
if (! isset($directories)) {
$check = true;
if (! file_exists($file)) {
if (! file_exists($fileInfo['file'])) {
$this->error(self::DOES_NOT_EXIST);
return false;
}
Expand All @@ -179,7 +166,7 @@ public function isValid($value, $file = null)
}

$check = true;
if (! file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
if (! file_exists($directory . DIRECTORY_SEPARATOR . $fileInfo['basename'])) {
$this->error(self::DOES_NOT_EXIST);
return false;
}
Expand Down
27 changes: 8 additions & 19 deletions src/File/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
use Traversable;
use Zend\Stdlib\ArrayUtils;
use Zend\Validator\AbstractValidator;
use Zend\Validator\File\FileInformationTrait;
use Zend\Validator\Exception;

/**
* Validator for the file extension of a file
*/
class Extension extends AbstractValidator
{
use FileInformationTrait;

/**
* @const string Error constants
*/
Expand Down Expand Up @@ -177,31 +180,17 @@ public function addExtension($extension)
*/
public function isValid($value, $file = null)
{
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'
);
}
$file = $value['tmp_name'];
$filename = $value['name'];
} else {
$file = $value;
$filename = basename($file);
}
$this->setValue($filename);
$fileInfo = $this->getFileInfo($value, $file);

$this->setValue($fileInfo['filename']);

// Is file readable ?
if (empty($file) || false === is_readable($file)) {
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
$this->error(self::NOT_FOUND);
return false;
}

$extension = substr($filename, strrpos($filename, '.') + 1);
$extension = substr($fileInfo['filename'], strrpos($fileInfo['filename'], '.') + 1);
$extensions = $this->getExtension();

if ($this->getCase() && (in_array($extension, $extensions))) {
Expand Down
Loading

0 comments on commit 64c3366

Please sign in to comment.