- Added min/max values
This commit is contained in:
parent
a9613222f8
commit
05975089e5
@ -15,6 +15,8 @@ class ContextField
|
|||||||
public bool $mandatory = false,
|
public bool $mandatory = false,
|
||||||
public ?int $minLength = null,
|
public ?int $minLength = null,
|
||||||
public ?int $maxLength = null,
|
public ?int $maxLength = null,
|
||||||
|
public ?int $minValue = null,
|
||||||
|
public ?int $maxValue = null,
|
||||||
public ?string $regexFormat = null,
|
public ?string $regexFormat = null,
|
||||||
public ?string $example = null,
|
public ?string $example = null,
|
||||||
public mixed $default = null,
|
public mixed $default = null,
|
||||||
@ -27,14 +29,21 @@ class ContextField
|
|||||||
throw new MandatoryFieldException("Mandatory field must be provided a value.");
|
throw new MandatoryFieldException("Mandatory field must be provided a value.");
|
||||||
}
|
}
|
||||||
elseif ($value !== null) {
|
elseif ($value !== null) {
|
||||||
if ($this->minLength || $this->maxLength) {
|
if (($this->minLength || $this->maxLength) && is_string($value)) {
|
||||||
if (is_string($value)) {
|
if (mb_strlen($value) < $this->minLength) {
|
||||||
if (mb_strlen($value) < $this->minLength) {
|
throw new MinimumLengthException("Minimum {$this->minLength} string length is required.");
|
||||||
throw new MinimumLengthException("Minimum {$this->minLength} string length is required.");
|
}
|
||||||
}
|
elseif (mb_strlen($value) > $this->maxLength) {
|
||||||
elseif (mb_strlen($value) > $this->maxLength) {
|
throw new MaximumLengthException("Maximum {$this->maxLength} string length has been exceeded.");
|
||||||
throw new MaximumLengthException("Maximum {$this->maxLength} string length has been exceeded.");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($this->minValue || $this->maxValue) && is_numeric($value)) {
|
||||||
|
if ($value < $this->minValue) {
|
||||||
|
throw new MinimumLengthException("Minimum value set at {$this->minValue}.");
|
||||||
|
}
|
||||||
|
elseif ($value > $this->maxValue) {
|
||||||
|
throw new MaximumLengthException("Maximum value set at {$this->maxValue}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user