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

Commit 64c3366

Browse files
committed
Merging develop to master in preparation for 2.12.0 release.
2 parents 3c28dfe + 6c19585 commit 64c3366

22 files changed

+633
-273
lines changed

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
sudo: false
2-
31
language: php
42

53
branches:
@@ -59,6 +57,15 @@ matrix:
5957
- php: 7.2
6058
env:
6159
- DEPS=latest
60+
- php: 7.3
61+
env:
62+
- DEPS=lowest
63+
- php: 7.3
64+
env:
65+
- DEPS=locked
66+
- php: 7.3
67+
env:
68+
- DEPS=latest
6269

6370
before_install:
6471
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

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

5+
## 2.12.0 - 2019-01-30
6+
7+
### Added
8+
9+
- [#250](https://github.com/zendframework/zend-validator/pull/250) adds support for PHP 7.3.
10+
11+
### Changed
12+
13+
- [#251](https://github.com/zendframework/zend-validator/pull/251) updates the logic of each of the various `Zend\Validator\File` validators
14+
to allow validating against PSR-7 `UploadedFileInterface` instances, expanding
15+
the support originally provided in version 2.11.0.
16+
17+
### Deprecated
18+
19+
- Nothing.
20+
21+
### Removed
22+
23+
- [#250](https://github.com/zendframework/zend-validator/pull/250) removes support for zend-stdlib v2 releases.
24+
25+
### Fixed
26+
27+
- Nothing.
28+
529
## 2.11.1 - 2019-01-29
630

731
### Added

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require": {
1616
"php": "^5.6 || ^7.0",
17-
"zendframework/zend-stdlib": "^2.7.6 || ^3.1",
17+
"zendframework/zend-stdlib": "^3.2.1",
1818
"container-interop/container-interop": "^1.1"
1919
},
2020
"require-dev": {
@@ -47,8 +47,8 @@
4747
"prefer-stable": true,
4848
"extra": {
4949
"branch-alias": {
50-
"dev-master": "2.11.x-dev",
51-
"dev-develop": "2.12.x-dev"
50+
"dev-master": "2.12.x-dev",
51+
"dev-develop": "2.13.x-dev"
5252
},
5353
"zf": {
5454
"component": "Zend\\Validator",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DateStep.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ protected function convertString($value, $addErrors = true)
166166
if (strpos($this->format, 'Y-\WW') === 0
167167
&& preg_match('/^([0-9]{4})\-W([0-9]{2})/', $value, $matches)
168168
) {
169-
$date = new DateTime;
169+
$date = new DateTime();
170170
$date->setISODate($matches[1], $matches[2]);
171171
} else {
172-
$date = DateTime::createFromFormat($this->format, $value, $this->timezone);
172+
$date = DateTime::createFromFormat($this->format, $value, new DateTimeZone('UTC'));
173173
}
174174

175175
// Invalid dates can show up as warnings (ie. "2007-02-99")

src/File/Crc32.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
namespace Zend\Validator\File;
1111

12-
use Zend\Validator\Exception;
12+
use Zend\Validator\File\FileInformationTrait;
1313

1414
/**
1515
* Validator for the crc32 hash of given files
1616
*/
1717
class Crc32 extends Hash
1818
{
19+
use FileInformationTrait;
20+
1921
/**
2022
* @const string Error constants
2123
*/
@@ -85,32 +87,18 @@ public function addCrc32($options)
8587
*/
8688
public function isValid($value, $file = null)
8789
{
88-
if (is_string($value) && is_array($file)) {
89-
// Legacy Zend\Transfer API support
90-
$filename = $file['name'];
91-
$file = $file['tmp_name'];
92-
} elseif (is_array($value)) {
93-
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
94-
throw new Exception\InvalidArgumentException(
95-
'Value array must be in $_FILES format'
96-
);
97-
}
98-
$file = $value['tmp_name'];
99-
$filename = $value['name'];
100-
} else {
101-
$file = $value;
102-
$filename = basename($file);
103-
}
104-
$this->setValue($filename);
90+
$fileInfo = $this->getFileInfo($value, $file);
91+
92+
$this->setValue($fileInfo['filename']);
10593

10694
// Is file readable ?
107-
if (empty($file) || false === is_readable($file)) {
95+
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
10896
$this->error(self::NOT_FOUND);
10997
return false;
11098
}
11199

112100
$hashes = array_unique(array_keys($this->getHash()));
113-
$filehash = hash_file('crc32', $file);
101+
$filehash = hash_file('crc32', $fileInfo['file']);
114102
if ($filehash === false) {
115103
$this->error(self::NOT_DETECTED);
116104
return false;

src/File/ExcludeExtension.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99

1010
namespace Zend\Validator\File;
1111

12+
use Zend\Validator\File\FileInformationTrait;
1213
use Zend\Validator\Exception;
1314

1415
/**
1516
* Validator for the excluding file extensions
1617
*/
1718
class ExcludeExtension extends Extension
1819
{
20+
use FileInformationTrait;
21+
1922
/**
2023
* @const string Error constants
2124
*/
@@ -40,31 +43,17 @@ class ExcludeExtension extends Extension
4043
*/
4144
public function isValid($value, $file = null)
4245
{
43-
if (is_string($value) && is_array($file)) {
44-
// Legacy Zend\Transfer API support
45-
$filename = $file['name'];
46-
$file = $file['tmp_name'];
47-
} elseif (is_array($value)) {
48-
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
49-
throw new Exception\InvalidArgumentException(
50-
'Value array must be in $_FILES format'
51-
);
52-
}
53-
$file = $value['tmp_name'];
54-
$filename = $value['name'];
55-
} else {
56-
$file = $value;
57-
$filename = basename($file);
58-
}
59-
$this->setValue($filename);
46+
$fileInfo = $this->getFileInfo($value, $file);
47+
48+
$this->setValue($fileInfo['filename']);
6049

6150
// Is file readable ?
62-
if (empty($file) || false === is_readable($file)) {
51+
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
6352
$this->error(self::NOT_FOUND);
6453
return false;
6554
}
6655

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

7059
if ($this->getCase() && (! in_array($extension, $extensions))) {

src/File/ExcludeMimeType.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
namespace Zend\Validator\File;
1111

1212
use finfo;
13-
use Zend\Validator\Exception;
13+
use Zend\Validator\File\FileInformationTrait;
1414

1515
/**
1616
* Validator for the mime type of a file
1717
*/
1818
class ExcludeMimeType extends MimeType
1919
{
20+
use FileInformationTrait;
21+
2022
const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
2123
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
2224
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
@@ -41,29 +43,12 @@ class ExcludeMimeType extends MimeType
4143
*/
4244
public function isValid($value, $file = null)
4345
{
44-
if (is_string($value) && is_array($file)) {
45-
// Legacy Zend\Transfer API support
46-
$filename = $file['name'];
47-
$filetype = $file['type'];
48-
$file = $file['tmp_name'];
49-
} elseif (is_array($value)) {
50-
if (! isset($value['tmp_name']) || ! isset($value['name']) || ! isset($value['type'])) {
51-
throw new Exception\InvalidArgumentException(
52-
'Value array must be in $_FILES format'
53-
);
54-
}
55-
$file = $value['tmp_name'];
56-
$filename = $value['name'];
57-
$filetype = $value['type'];
58-
} else {
59-
$file = $value;
60-
$filename = basename($file);
61-
$filetype = null;
62-
}
63-
$this->setValue($filename);
46+
$fileInfo = $this->getFileInfo($value, $file, true);
47+
48+
$this->setValue($fileInfo['filename']);
6449

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

8166
$this->type = null;
8267
if (! empty($this->finfo)) {
83-
$this->type = finfo_file($this->finfo, $file);
68+
$this->type = finfo_file($this->finfo, $fileInfo['file']);
8469
}
8570
}
8671

8772
if (empty($this->type) && $this->getHeaderCheck()) {
88-
$this->type = $filetype;
73+
$this->type = $fileInfo['filetype'];
8974
}
9075

9176
if (empty($this->type)) {

src/File/Exists.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
use Zend\Validator\AbstractValidator;
1313
use Zend\Validator\Exception;
14+
use Zend\Validator\File\FileInformationTrait;
1415

1516
/**
1617
* Validator which checks if the file already exists in the directory
1718
*/
1819
class Exists extends AbstractValidator
1920
{
21+
use FileInformationTrait;
22+
2023
/**
2124
* @const string Error constants
2225
*/
@@ -144,31 +147,15 @@ public function addDirectory($directory)
144147
*/
145148
public function isValid($value, $file = null)
146149
{
147-
if (is_string($value) && is_array($file)) {
148-
// Legacy Zend\Transfer API support
149-
$filename = $file['name'];
150-
$file = $file['tmp_name'];
151-
$this->setValue($filename);
152-
} elseif (is_array($value)) {
153-
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
154-
throw new Exception\InvalidArgumentException(
155-
'Value array must be in $_FILES format'
156-
);
157-
}
158-
$file = $value['tmp_name'];
159-
$filename = basename($file);
160-
$this->setValue($value['name']);
161-
} else {
162-
$file = $value;
163-
$filename = basename($file);
164-
$this->setValue($filename);
165-
}
150+
$fileInfo = $this->getFileInfo($value, $file, false, true);
151+
152+
$this->setValue($fileInfo['filename']);
166153

167154
$check = false;
168155
$directories = $this->getDirectory(true);
169156
if (! isset($directories)) {
170157
$check = true;
171-
if (! file_exists($file)) {
158+
if (! file_exists($fileInfo['file'])) {
172159
$this->error(self::DOES_NOT_EXIST);
173160
return false;
174161
}
@@ -179,7 +166,7 @@ public function isValid($value, $file = null)
179166
}
180167

181168
$check = true;
182-
if (! file_exists($directory . DIRECTORY_SEPARATOR . $filename)) {
169+
if (! file_exists($directory . DIRECTORY_SEPARATOR . $fileInfo['basename'])) {
183170
$this->error(self::DOES_NOT_EXIST);
184171
return false;
185172
}

src/File/Extension.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
use Traversable;
1313
use Zend\Stdlib\ArrayUtils;
1414
use Zend\Validator\AbstractValidator;
15+
use Zend\Validator\File\FileInformationTrait;
1516
use Zend\Validator\Exception;
1617

1718
/**
1819
* Validator for the file extension of a file
1920
*/
2021
class Extension extends AbstractValidator
2122
{
23+
use FileInformationTrait;
24+
2225
/**
2326
* @const string Error constants
2427
*/
@@ -177,31 +180,17 @@ public function addExtension($extension)
177180
*/
178181
public function isValid($value, $file = null)
179182
{
180-
if (is_string($value) && is_array($file)) {
181-
// Legacy Zend\Transfer API support
182-
$filename = $file['name'];
183-
$file = $file['tmp_name'];
184-
} elseif (is_array($value)) {
185-
if (! isset($value['tmp_name']) || ! isset($value['name'])) {
186-
throw new Exception\InvalidArgumentException(
187-
'Value array must be in $_FILES format'
188-
);
189-
}
190-
$file = $value['tmp_name'];
191-
$filename = $value['name'];
192-
} else {
193-
$file = $value;
194-
$filename = basename($file);
195-
}
196-
$this->setValue($filename);
183+
$fileInfo = $this->getFileInfo($value, $file);
184+
185+
$this->setValue($fileInfo['filename']);
197186

198187
// Is file readable ?
199-
if (empty($file) || false === is_readable($file)) {
188+
if (empty($fileInfo['file']) || false === is_readable($fileInfo['file'])) {
200189
$this->error(self::NOT_FOUND);
201190
return false;
202191
}
203192

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

207196
if ($this->getCase() && (in_array($extension, $extensions))) {

0 commit comments

Comments
 (0)