mirror of
https://github.com/n3w/helpers-cli-input.git
synced 2025-12-19 12:43:23 +00:00
Minor improvement to logic in AbstractInputHandler::validateInput(). Ensures that an input with a validator, but with a default value and no user suplied input, will have the default value used.
This commit is contained in:
parent
d501a680ff
commit
326a979302
1 changed files with 8 additions and 7 deletions
|
|
@ -68,17 +68,17 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface
|
||||||
if(!Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_REQUIRED)) {
|
if(!Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_REQUIRED)) {
|
||||||
self::checkRequiredAndRequiredValue($input, $this->input);
|
self::checkRequiredAndRequiredValue($input, $this->input);
|
||||||
}
|
}
|
||||||
// There is a default value, input has not been set, and there
|
// There is a default value and input has not been set. Assign the
|
||||||
// is no validator
|
// default value to the result.
|
||||||
if (
|
if (
|
||||||
null !== $input->default() &&
|
null !== $input->default() &&
|
||||||
null === $this->find($input->name()) &&
|
null === $this->find($input->name())
|
||||||
null === $input->validator()
|
|
||||||
) {
|
) {
|
||||||
$result = $input->default();
|
$result = $input->default();
|
||||||
|
|
||||||
// Input has been set and it has a validator. Skip this if
|
// Input has been set AND it has a validator. Run the validator over the
|
||||||
// FLAG_VALIDATION_SKIP_CUSTOM is set
|
// input. Note, this will be skipped if FLAG_VALIDATION_SKIP_CUSTOM is
|
||||||
|
// set
|
||||||
} elseif (null !== $this->find($input->name()) && null !== $input->validator() && !Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_CUSTOM)) {
|
} elseif (null !== $this->find($input->name()) && null !== $input->validator() && !Flags\is_flag_set($flags, self::FLAG_VALIDATION_SKIP_CUSTOM)) {
|
||||||
$validator = $input->validator();
|
$validator = $input->validator();
|
||||||
|
|
||||||
|
|
@ -94,7 +94,8 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface
|
||||||
throw new Exceptions\InputValidationFailedException($input, 0, $ex);
|
throw new Exceptions\InputValidationFailedException($input, 0, $ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// No default, no validator, but may or may not have been set
|
// No default, but may or may not have been set so assign whatever value
|
||||||
|
// it might have to the result
|
||||||
} else {
|
} else {
|
||||||
$result = $this->find($input->name());
|
$result = $this->find($input->name());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue