enum max length validation

This commit is contained in:
Yuri Kuznetsov
2022-07-14 12:04:14 +03:00
parent 9abb977844
commit bbdf8edce8
2 changed files with 23 additions and 2 deletions
@@ -40,6 +40,8 @@ class EnumType
private Defs $defs;
private const DEFAULT_MAX_LENGTH = 255;
public function __construct(Metadata $metadata, Defs $defs)
{
$this->metadata = $metadata;
@@ -94,6 +96,23 @@ class EnumType
return in_array($value, $optionList);
}
public function checkMaxLength(Entity $entity, string $field, ?int $validationValue): bool
{
if (!$this->isNotEmpty($entity, $field)) {
return true;
}
$value = $entity->get($field);
$maxLength = $validationValue ?? self::DEFAULT_MAX_LENGTH;
if (mb_strlen($value) > $maxLength) {
return false;
}
return true;
}
protected function isNotEmpty(Entity $entity, string $field): bool
{
return $entity->has($field) && $entity->get($field) !== null;
@@ -50,10 +50,12 @@
],
"validationList": [
"required",
"valid"
"valid",
"maxLength"
],
"mandatoryValidationList": [
"valid"
"valid",
"maxLength"
],
"filter": true,
"fieldDefs": {