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

Commit a3c66bf

Browse files
committed
[bc\break] Remove deprecated and validators auto injections
* Remove AllowEmpty / ContinueIfEmpty deprecated on 2.4.8. Zend\Validator\NotEmpty should be added to the ValidatorChain when expected. * Remove UploadFile validator auto injection Zend\Validator\File\UploadFile should be added to the ValidatorChain when expected.
1 parent 52d3ff4 commit a3c66bf

10 files changed

+45
-940
lines changed

src/ArrayInput.php

-12
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,10 @@ public function isValid($context = null)
7676
return false;
7777
}
7878

79-
if (!$this->continueIfEmpty() && !$this->allowEmpty()) {
80-
$this->injectNotEmptyValidator();
81-
}
8279
$validator = $this->getValidatorChain();
8380
$values = $this->getValue();
8481
$result = true;
8582
foreach ($values as $value) {
86-
$empty = ($value === null || $value === '' || $value === []);
87-
if ($empty && !$this->isRequired() && !$this->continueIfEmpty()) {
88-
$result = true;
89-
continue;
90-
}
91-
if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) {
92-
$result = true;
93-
continue;
94-
}
9583
$result = $validator->isValid($value, $context);
9684
if (!$result) {
9785
if ($hasFallback) {

src/EmptyContextInterface.php

-31
This file was deleted.

src/Factory.php

-16
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,6 @@ public function createInput($inputSpecification)
212212
case 'required':
213213
$input->setRequired($value);
214214
break;
215-
case 'allow_empty':
216-
$input->setAllowEmpty($value);
217-
if (!isset($inputSpecification['required'])) {
218-
$input->setRequired(!$value);
219-
}
220-
break;
221-
case 'continue_if_empty':
222-
if (!$input instanceof Input) {
223-
throw new Exception\RuntimeException(sprintf(
224-
'%s "continue_if_empty" can only set to inputs of type "%s"',
225-
__METHOD__,
226-
Input::class
227-
));
228-
}
229-
$input->setContinueIfEmpty($inputSpecification['continue_if_empty']);
230-
break;
231215
case 'error_message':
232216
$input->setErrorMessage($value);
233217
break;

src/FileInput.php

-109
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
namespace Zend\InputFilter;
1111

12-
use Zend\Validator\File\UploadFile as UploadValidator;
13-
1412
/**
1513
* FileInput is a special Input type for handling uploaded files.
1614
*
@@ -32,29 +30,6 @@ class FileInput extends Input
3230
*/
3331
protected $isValid = false;
3432

35-
/**
36-
* @var bool
37-
*/
38-
protected $autoPrependUploadValidator = true;
39-
40-
/**
41-
* @param bool $value Enable/Disable automatically prepending an Upload validator
42-
* @return FileInput
43-
*/
44-
public function setAutoPrependUploadValidator($value)
45-
{
46-
$this->autoPrependUploadValidator = $value;
47-
return $this;
48-
}
49-
50-
/**
51-
* @return bool
52-
*/
53-
public function getAutoPrependUploadValidator()
54-
{
55-
return $this->autoPrependUploadValidator;
56-
}
57-
5833
/**
5934
* @return mixed
6035
*/
@@ -83,29 +58,6 @@ public function getValue()
8358
return $value;
8459
}
8560

86-
/**
87-
* Checks if the raw input value is an empty file input eg: no file was uploaded
88-
*
89-
* @param $rawValue
90-
* @return bool
91-
*/
92-
public function isEmptyFile($rawValue)
93-
{
94-
if (!is_array($rawValue)) {
95-
return true;
96-
}
97-
98-
if (isset($rawValue['error']) && $rawValue['error'] === UPLOAD_ERR_NO_FILE) {
99-
return true;
100-
}
101-
102-
if (count($rawValue) === 1 && isset($rawValue[0])) {
103-
return $this->isEmptyFile($rawValue[0]);
104-
}
105-
106-
return false;
107-
}
108-
10961
/**
11062
* @param mixed $context Extra "context" to provide the validator
11163
* @return bool
@@ -114,10 +66,7 @@ public function isValid($context = null)
11466
{
11567
$rawValue = $this->getRawValue();
11668
$hasValue = $this->hasValue();
117-
$empty = $this->isEmptyFile($rawValue);
11869
$required = $this->isRequired();
119-
$allowEmpty = $this->allowEmpty();
120-
$continueIfEmpty = $this->continueIfEmpty();
12170

12271
if (! $hasValue && ! $required) {
12372
return true;
@@ -130,15 +79,6 @@ public function isValid($context = null)
13079
return false;
13180
}
13281

133-
if ($empty && ! $required && ! $continueIfEmpty) {
134-
return true;
135-
}
136-
137-
if ($empty && $allowEmpty && ! $continueIfEmpty) {
138-
return true;
139-
}
140-
141-
$this->injectUploadValidator();
14282
$validator = $this->getValidatorChain();
14383
//$value = $this->getValue(); // Do not run the filters yet for File uploads (see getValue())
14484

@@ -168,53 +108,4 @@ public function isValid($context = null)
168108

169109
return $this->isValid;
170110
}
171-
172-
/**
173-
* @return void
174-
*/
175-
protected function injectUploadValidator()
176-
{
177-
if (!$this->autoPrependUploadValidator) {
178-
return;
179-
}
180-
$chain = $this->getValidatorChain();
181-
182-
// Check if Upload validator is already first in chain
183-
$validators = $chain->getValidators();
184-
if (isset($validators[0]['instance'])
185-
&& $validators[0]['instance'] instanceof UploadValidator
186-
) {
187-
$this->autoPrependUploadValidator = false;
188-
return;
189-
}
190-
191-
$chain->prependByName('fileuploadfile', [], true);
192-
$this->autoPrependUploadValidator = false;
193-
}
194-
195-
/**
196-
* @deprecated 2.4.8 See note on parent class. Removal does not affect this class.
197-
*
198-
* No-op, NotEmpty validator does not apply for FileInputs.
199-
* See also: BaseInputFilter::isValid()
200-
*
201-
* @return void
202-
*/
203-
protected function injectNotEmptyValidator()
204-
{
205-
$this->notEmptyValidator = true;
206-
}
207-
208-
/**
209-
* @param InputInterface $input
210-
* @return FileInput
211-
*/
212-
public function merge(InputInterface $input)
213-
{
214-
parent::merge($input);
215-
if ($input instanceof FileInput) {
216-
$this->setAutoPrependUploadValidator($input->getAutoPrependUploadValidator());
217-
}
218-
return $this;
219-
}
220111
}

0 commit comments

Comments
 (0)