-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathBetween.php
More file actions
executable file
·37 lines (31 loc) · 1.05 KB
/
Between.php
File metadata and controls
executable file
·37 lines (31 loc) · 1.05 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
<?php
declare(strict_types=1);
namespace Sirius\Validation\Rule;
class Between extends AbstractRule
{
const OPTION_MIN = 'min';
const OPTION_MAX = 'max';
const MESSAGE = 'This input must be between {min} and {max}';
const LABELED_MESSAGE = '{label} must be between {min} and {max}';
protected array $optionsIndexMap = [
0 => self::OPTION_MIN,
1 => self::OPTION_MAX
];
public function validate(mixed $value, ?string $valueIdentifier = null): bool
{
$this->value = $value;
$minValidator = new LessThan();
if (isset($this->options['max'])) {
$minValidator->setOption('max', $this->options['max']);
}
$maxValidator = new GreaterThan();
if (isset($this->options['min'])) {
$maxValidator->setOption('min', $this->options['min']);
}
$this->success = $minValidator->validate($value, $valueIdentifier) && $maxValidator->validate(
$value,
$valueIdentifier
);
return $this->success;
}
}