enum max length validation
This commit is contained in:
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user