1 | <?php |
||
32 | class CompareValidator implements ValidatorInterface |
||
33 | { |
||
34 | |||
35 | use AllowEmpty, |
||
36 | Messages, |
||
37 | Strict, |
||
38 | OnScenario, |
||
39 | Safe, |
||
40 | SkipOnError; |
||
41 | |||
42 | /** |
||
43 | * @var string the name of the attribute to be compared with |
||
44 | */ |
||
45 | public $compareAttribute; |
||
46 | |||
47 | /** |
||
48 | * @var string the constant value to be compared with |
||
49 | */ |
||
50 | public $compareValue; |
||
51 | |||
52 | /** |
||
53 | * @var string the operator for comparison. Defaults to '='. |
||
54 | * The followings are valid operators: |
||
55 | * <ul> |
||
56 | * <li>'=' or '==': validates to see if the two values are equal. If {@link strict} is true, the comparison |
||
57 | * will be done in strict mode (i.e. checking value type as well).</li> |
||
58 | * <li>'!=': validates to see if the two values are NOT equal. If {@link strict} is true, the comparison |
||
59 | * will be done in strict mode (i.e. checking value type as well).</li> |
||
60 | * <li>'>': validates to see if the value being validated is greater than the value being compared with.</li> |
||
61 | * <li>'>=': validates to see if the value being validated is greater than or equal to the value being compared with.</li> |
||
62 | * <li>'<': validates to see if the value being validated is less than the value being compared with.</li> |
||
63 | * <li>'<=': validates to see if the value being validated is less than or equal to the value being compared with.</li> |
||
64 | * </ul> |
||
65 | */ |
||
66 | public $operator = '='; |
||
67 | |||
68 | /** |
||
69 | * @Label('{attribute} must be repeated exactly') |
||
70 | * @var string |
||
71 | */ |
||
72 | public $msgRepeat = ''; |
||
73 | |||
74 | /** |
||
75 | * @Label('{attribute} must not be equal to "{compareValue}"') |
||
76 | * @var string |
||
77 | */ |
||
78 | public $msgEq = ''; |
||
79 | |||
80 | /** |
||
81 | * @Label('{attribute} must be greater than "{compareValue}"') |
||
82 | * @var string |
||
83 | */ |
||
84 | public $msgGt = ''; |
||
85 | |||
86 | /** |
||
87 | * @Label('{attribute} must be greater than or equal to "{compareValue}"') |
||
88 | * @var string |
||
89 | */ |
||
90 | public $msgGte = ''; |
||
91 | |||
92 | /** |
||
93 | * @Label('{attribute} must be less than "{compareValue}"') |
||
94 | * @var string |
||
95 | */ |
||
96 | public $msgLt = ''; |
||
97 | |||
98 | /** |
||
99 | * @Label('{attribute} must be less than or equal to "{compareValue}"') |
||
100 | * @var string |
||
101 | */ |
||
102 | public $msgLte = ''; |
||
103 | |||
104 | 14 | public function isValid(AnnotatedInterface $model, $attribute) |
|
175 | |||
176 | } |
||
177 |