-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessThan.php
More file actions
50 lines (44 loc) · 1.2 KB
/
Copy pathLessThan.php
File metadata and controls
50 lines (44 loc) · 1.2 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
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Quatrevieux\Form\Validator\Constraint;
use Attribute;
/**
* Check that the field value is less than the given value
*
* Numeric and string values are supported.
* To ensure that the comparison is done in the same type, add a typehint to the field and use the same type on the constraint's value.
*
* Example:
* <code>
* class MyForm
* {
* #[LessThan(10)]
* public int $foo;
* }
* </code>
*
* @see LessThanOrEqual for a less or equal comparison
* @see GreaterThanOrEqual for the opposite constraint
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
final class LessThan extends AbstractComparisonConstraint
{
public const CODE = '4b394c37-65be-5f85-8972-347b98d7bc0a';
public function __construct(int|float|string|bool $value, string $message = 'The value should be less than {{ value }}.')
{
parent::__construct($value, $message);
}
/**
* {@inheritdoc}
*/
protected function compare(float|bool|int|string $actual, float|bool|int|string $expected): bool
{
return $actual < $expected;
}
/**
* {@inheritdoc}
*/
protected function operator(): string
{
return '<';
}
}