|
|
@ -59,12 +59,29 @@ trait TCommandWithValidation {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function validateArguments (InputInterface $input, OutputInterface $output): void {
|
|
|
|
protected function validateArguments (InputInterface $input, OutputInterface $output): void {
|
|
|
|
foreach ($this->argumentsValidator as $argumentName => $argumentValidator) {
|
|
|
|
foreach ($this->argumentsValidator as $argumentName => $argumentValidator) {
|
|
|
|
if ($input->hasArgument($argumentName)) {
|
|
|
|
//region Check the argument still exists
|
|
|
|
if (!$argumentValidator->validate($input->getArgument($argumentName))) {
|
|
|
|
if (!$input->hasArgument($argumentName)) {
|
|
|
|
throw new InvalidValueException(sprintf('The "%s" argument has not a valid value', $argumentName));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$input->setArgument($argumentName, $argumentValidator->getValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Get the argument value
|
|
|
|
|
|
|
|
$argumentValue = $input->getArgument($argumentName);
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Check the argument value is not Null
|
|
|
|
|
|
|
|
if ($argumentValue === null) {
|
|
|
|
|
|
|
|
// If the value is strictly Null (the default value), don't check it → skip
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//region Check the value is valid
|
|
|
|
|
|
|
|
if (!$argumentValidator->validate($argumentValue)) {
|
|
|
|
|
|
|
|
throw new InvalidValueException(sprintf('The "%s" argument has not a valid value', $argumentName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Replace the value by the one extracted from the validator
|
|
|
|
|
|
|
|
$input->setArgument($argumentName, $argumentValidator->getValue());
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -79,12 +96,29 @@ trait TCommandWithValidation {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function validateOptions (InputInterface $input, OutputInterface $output): void {
|
|
|
|
protected function validateOptions (InputInterface $input, OutputInterface $output): void {
|
|
|
|
foreach ($this->optionsValidator as $optionName => $optionValidator) {
|
|
|
|
foreach ($this->optionsValidator as $optionName => $optionValidator) {
|
|
|
|
if ($input->hasOption($optionName)) {
|
|
|
|
//region Check the option still exists
|
|
|
|
if (!$optionValidator->validate($input->getOption($optionName))) {
|
|
|
|
if (!$input->hasOption($optionName)) {
|
|
|
|
throw new InvalidValueException(sprintf('The "--%s" option has not a valid value', $optionName));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$input->setOption($optionName, $optionValidator->getValue());
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Get and check the option value
|
|
|
|
|
|
|
|
$optionValue = $input->getOption($optionName);
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Check the option value is NOT Null or False
|
|
|
|
|
|
|
|
if ($optionValue === null || $optionValue === false) {
|
|
|
|
|
|
|
|
// If the value is strictly Null (the default value or not provided) or False (the default value), don't check it → skip
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//region Check the value is valid
|
|
|
|
|
|
|
|
if (!$optionValidator->validate($optionValue)) {
|
|
|
|
|
|
|
|
throw new InvalidValueException(sprintf('The "--%s" option has not a valid value', $optionName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
|
|
//region Replace the value by the one extracted from the validator
|
|
|
|
|
|
|
|
$input->setOption($optionName, $optionValidator->getValue());
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|