mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user