-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathLength.php
More file actions
executable file
·39 lines (33 loc) · 1.15 KB
/
Length.php
File metadata and controls
executable file
·39 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Sirius\Validation\Rule;
class Length extends AbstractRule
{
const OPTION_MIN = 'min';
const OPTION_MAX = 'max';
const OPTION_ENCODING = 'encoding';
const MESSAGE = 'This input must be between {min} and {max} characters long';
const LABELED_MESSAGE = '{label} must be between {min} and {max} characters long';
protected array $optionsIndexMap = [
0 => self::OPTION_MIN,
1 => self::OPTION_MAX,
2 => self::OPTION_ENCODING
];
public function validate(mixed $value, ?string $valueIdentifier = null): bool
{
$this->value = $value;
$maxValidator = new MaxLength();
if (isset($this->options['max'])) {
$maxValidator->setOption('max', $this->options['max']);
}
$minValidator = new MinLength();
if (isset($this->options['min'])) {
$minValidator->setOption('min', $this->options['min']);
}
$this->success = $minValidator->validate($value, $valueIdentifier) && $maxValidator->validate(
$value,
$valueIdentifier
);
return $this->success;
}
}