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)) {
|
||||
self::checkRequiredAndRequiredValue($input, $this->input);
|
||||
}
|
||||
// There is a default value, input has not been set, and there
|
||||
// is no validator
|
||||
// There is a default value and input has not been set. Assign the
|
||||
// default value to the result.
|
||||
if (
|
||||
null !== $input->default() &&
|
||||
null === $this->find($input->name()) &&
|
||||
null === $input->validator()
|
||||
null === $this->find($input->name())
|
||||
) {
|
||||
$result = $input->default();
|
||||
|
||||
// Input has been set and it has a validator. Skip this if
|
||||
// FLAG_VALIDATION_SKIP_CUSTOM is set
|
||||
// Input has been set AND it has a validator. Run the validator over the
|
||||
// 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)) {
|
||||
$validator = $input->validator();
|
||||
|
||||
|
|
@ -94,7 +94,8 @@ abstract class AbstractInputHandler implements Interfaces\InputHandlerInterface
|
|||
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 {
|
||||
$result = $this->find($input->name());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue