N°6414 Move existing AbstractSimpleField::Validate impl to custom validators

- LinkedSetField
- SelectObjectField
- MultipleChoicesField (warning this hierarchy contains non multiple value fields like SelectField !)

Also change AbstractValidator::Validate signature : now we are returning an array of error messages, so that we can return multiple ones
This commit is contained in:
Pierre Goiffon
2023-06-28 17:56:04 +02:00
parent d085f15b6d
commit 6cc2d49cd5
20 changed files with 526 additions and 172 deletions

View File

@@ -20,19 +20,20 @@ abstract class AbstractValidator
/** @var string message / dict key to use when an error occurs */
protected string $sErrorMessage;
public function __construct(?string $sErrorMessage)
public function __construct(?string $sErrorMessage = null)
{
if (false === utils::IsNullOrEmptyString($sErrorMessage)) {
$this->sErrorMessage = $sErrorMessage;
} else {
$this->sErrorMessage = self::DEFAULT_ERROR_MESSAGE;
}
else {
$this->sErrorMessage = static::DEFAULT_ERROR_MESSAGE;
}
}
/**
* @param mixed $value
*
* @return array<bool,?string> boolean valid for valid / invalid, and error message if invalid
* @return string[] list of error messages, empty array if no error
*/
abstract public function Validate($value): array;