1 | <?php |
||
18 | class RequiredValidator extends Validator |
||
19 | { |
||
20 | /** |
||
21 | * @var bool whether to skip this validator if the value being validated is empty. |
||
22 | */ |
||
23 | public $skipOnEmpty = false; |
||
24 | /** |
||
25 | * @var mixed the desired value that the attribute must have. |
||
26 | * If this is null, the validator will validate that the specified attribute is not empty. |
||
27 | * If this is set as a value that is not null, the validator will validate that |
||
28 | * the attribute has a value that is the same as this property value. |
||
29 | * Defaults to null. |
||
30 | * @see strict |
||
31 | */ |
||
32 | public $requiredValue; |
||
33 | /** |
||
34 | * @var bool whether the comparison between the attribute value and [[requiredValue]] is strict. |
||
35 | * When this is true, both the values and types must match. |
||
36 | * Defaults to false, meaning only the values need to match. |
||
37 | * Note that when [[requiredValue]] is null, if this property is true, the validator will check |
||
38 | * if the attribute value is null; If this property is false, the validator will call [[isEmpty]] |
||
39 | * to check if the attribute value is empty. |
||
40 | */ |
||
41 | public $strict = false; |
||
42 | /** |
||
43 | * @var string the user-defined error message. It may contain the following placeholders which |
||
44 | * will be replaced accordingly by the validator: |
||
45 | * |
||
46 | * - `{attribute}`: the label of the attribute being validated |
||
47 | * - `{value}`: the value of the attribute being validated |
||
48 | * - `{requiredValue}`: the value of [[requiredValue]] |
||
49 | */ |
||
50 | public $message; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 26 | public function init() |
|
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | */ |
||
68 | 11 | protected function validateValue($value) |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function clientValidateAttribute($model, $attribute, $view) |
||
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | public function getClientOptions($model, $attribute) |
||
121 | } |
||
122 |