-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathLessThan.php
More file actions
executable file
·38 lines (31 loc) · 968 Bytes
/
LessThan.php
File metadata and controls
executable file
·38 lines (31 loc) · 968 Bytes
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
<?php
declare(strict_types=1);
namespace Sirius\Validation\Rule;
class LessThan extends AbstractRule
{
const OPTION_MAX = 'max';
const OPTION_INCLUSIVE = 'inclusive';
const MESSAGE = 'This input should be less than {max}';
const LABELED_MESSAGE = '{label} should be less than {max}';
protected array $options = [
'inclusive' => true
];
protected array $optionsIndexMap = [
0 => self::OPTION_MAX,
1 => self::OPTION_INCLUSIVE
];
public function validate(mixed $value, ?string $valueIdentifier = null): bool
{
$this->value = $value;
if (!isset($this->options['max'])) {
$this->success = true;
} else {
if ($this->options['inclusive']) {
$this->success = $value <= $this->options['max'];
} else {
$this->success = $value < $this->options['max'];
}
}
return $this->success;
}
}