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

[bc\break] Remove deprecated and validators auto injections #83

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
112 changes: 0 additions & 112 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 @@ -21,9 +19,6 @@
* 2. The validators are run **before** the filters (the opposite behavior of Input).
* This is so is_uploaded_file() validation can be run prior to any filters that
* may rename/move/modify the file.
*
* 3. Instead of adding a NotEmpty validator, it will (by default) automatically add
* a Zend\Validator\File\Upload validator.
*/
class FileInput extends Input
{
Expand All @@ -32,29 +27,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 +55,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 +63,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 +76,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 +105,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