-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdenticalTo.php
More file actions
52 lines (46 loc) · 1.28 KB
/
Copy pathIdenticalTo.php
File metadata and controls
52 lines (46 loc) · 1.28 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
51
52
<?php
namespace Quatrevieux\Form\Validator\Constraint;
use Attribute;
use Quatrevieux\Form\Transformer\Field\Cast;
/**
* Check that the field value is same as to the given value
* This comparison use the strict comparison operator (===).
*
* Numeric and string values are supported.
* The value type must be the same as the field type, and the field value must be cast using typehint or {@see Cast} transformer.
*
* Example:
* <code>
* class MyForm
* {
* #[IdenticalTo(10)]
* public int $foo;
* }
* </code>
*
* @see EqualTo for a simple comparison
* @see NotIdenticalTo for the opposite constraint
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
final class IdenticalTo extends AbstractComparisonConstraint
{
public const CODE = '8072727f-84e9-580d-9abb-950ca33b4d55';
public function __construct(int|float|string|bool $value, string $message = 'The value should be same as {{ 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 '===';
}
}