Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Closed
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
49 changes: 25 additions & 24 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,28 @@ protected function validateInputs(array $inputs, $data = [], $context = null)

foreach ($inputs as $name) {
$input = $this->inputs[$name];

// Validate an input filter
if ($input instanceof InputFilterInterface) {
if (!$input->isValid($context)) {
$this->invalidInputs[$name] = $input;
$valid = false;
continue;
}
$this->validInputs[$name] = $input;
continue;
}

// If input is not InputInterface then silently continue (BC safe)
if (!$input instanceof InputInterface) {
continue;
}

$hasFallback = ($input instanceof Input && $input->hasFallback());

// If the value is required, not present in the data set, and
// has no fallback, validation fails.
if (!array_key_exists($name, $data)
&& $input instanceof InputInterface
&& $input->isRequired()
&& !$hasFallback
) {
Expand All @@ -266,7 +282,6 @@ protected function validateInputs(array $inputs, $data = [], $context = null)
// has a fallback, validation passes, and we set the input
// value to the fallback.
if (!array_key_exists($name, $data)
&& $input instanceof InputInterface
&& $input->isRequired()
&& $hasFallback
) {
Expand All @@ -279,34 +294,20 @@ protected function validateInputs(array $inputs, $data = [], $context = null)
$data[$name] = null;
}

// Validate an input filter
if ($input instanceof InputFilterInterface) {
if (!$input->isValid($context)) {
$this->invalidInputs[$name] = $input;
$valid = false;
continue;
}
$this->validInputs[$name] = $input;
continue;
}

// Validate an input
if ($input instanceof InputInterface) {
$inputContext = $context ?: $data;
$inputContext = $context ?: $data;

if (!$input->isValid($inputContext)) {
// Validation failure
$this->invalidInputs[$name] = $input;
$valid = false;
if (!$input->isValid($inputContext)) {
// Validation failure
$this->invalidInputs[$name] = $input;
$valid = false;

if ($input->breakOnFailure()) {
return false;
}
continue;
if ($input->breakOnFailure()) {
return false;
}
$this->validInputs[$name] = $input;
continue;
}
$this->validInputs[$name] = $input;
}

return $valid;
Expand Down