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

Commit

Permalink
[bc\break] Remove deprecated and validators auto injections
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Maks3w committed Dec 18, 2015
1 parent 52d3ff4 commit a3c66bf
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 940 deletions.
12 changes: 0 additions & 12 deletions src/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,10 @@ public function isValid($context = null)
return false;
}

if (!$this->continueIfEmpty() && !$this->allowEmpty()) {
$this->injectNotEmptyValidator();
}
$validator = $this->getValidatorChain();
$values = $this->getValue();
$result = true;
foreach ($values as $value) {
$empty = ($value === null || $value === '' || $value === []);
if ($empty && !$this->isRequired() && !$this->continueIfEmpty()) {
$result = true;
continue;
}
if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) {
$result = true;
continue;
}
$result = $validator->isValid($value, $context);
if (!$result) {
if ($hasFallback) {
Expand Down
31 changes: 0 additions & 31 deletions src/EmptyContextInterface.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,6 @@ public function createInput($inputSpecification)
case 'required':
$input->setRequired($value);
break;
case 'allow_empty':
$input->setAllowEmpty($value);
if (!isset($inputSpecification['required'])) {
$input->setRequired(!$value);
}
break;
case 'continue_if_empty':
if (!$input instanceof Input) {
throw new Exception\RuntimeException(sprintf(
'%s "continue_if_empty" can only set to inputs of type "%s"',
__METHOD__,
Input::class
));
}
$input->setContinueIfEmpty($inputSpecification['continue_if_empty']);
break;
case 'error_message':
$input->setErrorMessage($value);
break;
Expand Down
109 changes: 0 additions & 109 deletions src/FileInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Zend\InputFilter;

use Zend\Validator\File\UploadFile as UploadValidator;

/**
* FileInput is a special Input type for handling uploaded files.
*
Expand All @@ -32,29 +30,6 @@ class FileInput extends Input
*/
protected $isValid = false;

/**
* @var bool
*/
protected $autoPrependUploadValidator = true;

/**
* @param bool $value Enable/Disable automatically prepending an Upload validator
* @return FileInput
*/
public function setAutoPrependUploadValidator($value)
{
$this->autoPrependUploadValidator = $value;
return $this;
}

/**
* @return bool
*/
public function getAutoPrependUploadValidator()
{
return $this->autoPrependUploadValidator;
}

/**
* @return mixed
*/
Expand Down Expand Up @@ -83,29 +58,6 @@ public function getValue()
return $value;
}

/**
* Checks if the raw input value is an empty file input eg: no file was uploaded
*
* @param $rawValue
* @return bool
*/
public function isEmptyFile($rawValue)
{
if (!is_array($rawValue)) {
return true;
}

if (isset($rawValue['error']) && $rawValue['error'] === UPLOAD_ERR_NO_FILE) {
return true;
}

if (count($rawValue) === 1 && isset($rawValue[0])) {
return $this->isEmptyFile($rawValue[0]);
}

return false;
}

/**
* @param mixed $context Extra "context" to provide the validator
* @return bool
Expand All @@ -114,10 +66,7 @@ public function isValid($context = null)
{
$rawValue = $this->getRawValue();
$hasValue = $this->hasValue();
$empty = $this->isEmptyFile($rawValue);
$required = $this->isRequired();
$allowEmpty = $this->allowEmpty();
$continueIfEmpty = $this->continueIfEmpty();

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

if ($empty && ! $required && ! $continueIfEmpty) {
return true;
}

if ($empty && $allowEmpty && ! $continueIfEmpty) {
return true;
}

$this->injectUploadValidator();
$validator = $this->getValidatorChain();
//$value = $this->getValue(); // Do not run the filters yet for File uploads (see getValue())

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

return $this->isValid;
}

/**
* @return void
*/
protected function injectUploadValidator()
{
if (!$this->autoPrependUploadValidator) {
return;
}
$chain = $this->getValidatorChain();

// Check if Upload validator is already first in chain
$validators = $chain->getValidators();
if (isset($validators[0]['instance'])
&& $validators[0]['instance'] instanceof UploadValidator
) {
$this->autoPrependUploadValidator = false;
return;
}

$chain->prependByName('fileuploadfile', [], true);
$this->autoPrependUploadValidator = false;
}

/**
* @deprecated 2.4.8 See note on parent class. Removal does not affect this class.
*
* No-op, NotEmpty validator does not apply for FileInputs.
* See also: BaseInputFilter::isValid()
*
* @return void
*/
protected function injectNotEmptyValidator()
{
$this->notEmptyValidator = true;
}

/**
* @param InputInterface $input
* @return FileInput
*/
public function merge(InputInterface $input)
{
parent::merge($input);
if ($input instanceof FileInput) {
$this->setAutoPrependUploadValidator($input->getAutoPrependUploadValidator());
}
return $this;
}
}
Loading

0 comments on commit a3c66bf

Please sign in to comment.