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

@@ -18,23 +18,23 @@ abstract class AbstractRegexpValidator extends AbstractValidator
protected string $sRegExp;
public function __construct(?string $sErrorMessage = null)
{
$this->sRegExp = static::DEFAULT_REGEXP;
parent::__construct($sErrorMessage);
}
public function __construct(?string $sErrorMessage = null)
{
$this->sRegExp = static::DEFAULT_REGEXP;
parent::__construct($sErrorMessage);
}
public function Validate($value): array
{
if (is_null($value)) {
$value = ''; // calling preg_match with null as subject is deprecated since PHP 8.1
}
if (preg_match($this->GetRegExp(true), $value)) {
return [true, null];
}
public function Validate($value): array
{
if (is_null($value)) {
$value = ''; // calling preg_match with null as subject is deprecated since PHP 8.1
}
if (preg_match($this->GetRegExp(true), $value)) {
return [];
}
return [false, $this->sErrorMessage];
}
return [$this->sErrorMessage];
}
/**
* Returns the regular expression of the validator.