-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessThanOrEqual.php
More file actions
50 lines (44 loc) · 1.23 KB
/
Copy pathLessThanOrEqual.php
File metadata and controls
50 lines (44 loc) · 1.23 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 or equal to 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
* {
* #[LessThanOrEqual(10)]
* public int $foo;
* }
* </code>
*
* @see LessThan for a less without equal comparison
* @see GreaterThan for the opposite constraint
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
final class LessThanOrEqual extends AbstractComparisonConstraint
{
public const CODE = '00ca521f-5da3-5336-8469-20d7e571c2dc';
public function __construct(int|float|string|bool $value, string $message = 'The value should be less than or equal to {{ 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 '<=';
}
}