1 | <?php |
||
41 | class EachValidator extends Validator |
||
42 | { |
||
43 | /** |
||
44 | * @var array|Validator definition of the validation rule, which should be used on array values. |
||
45 | * It should be specified in the same format as at [[\yii\base\Model::rules()]], except it should not |
||
46 | * contain attribute list as the first element. |
||
47 | * For example: |
||
48 | * |
||
49 | * ```php |
||
50 | * ['integer'] |
||
51 | * ['match', 'pattern' => '/[a-z]/is'] |
||
52 | * ``` |
||
53 | * |
||
54 | * Please refer to [[\yii\base\Model::rules()]] for more details. |
||
55 | */ |
||
56 | public $rule; |
||
57 | /** |
||
58 | * @var bool whether to use error message composed by validator declared via [[rule]] if its validation fails. |
||
59 | * If enabled, error message specified for this validator itself will appear only if attribute value is not an array. |
||
60 | * If disabled, own error message value will be used always. |
||
61 | */ |
||
62 | public $allowMessageFromRule = true; |
||
63 | /** |
||
64 | * @var bool whether to stop validation once first error among attribute value elements is detected. |
||
65 | * When enabled validation will produce single error message on attribute, when disabled - multiple |
||
66 | * error messages mya appear: one per each invalid value. |
||
67 | * Note that this option will affect only [[validateAttribute()]] value, while [[validateValue()]] will |
||
68 | * not be affected. |
||
69 | * @since 2.0.11 |
||
70 | */ |
||
71 | public $stopOnFirstError = true; |
||
72 | |||
73 | /** |
||
74 | * @var Validator validator instance. |
||
75 | */ |
||
76 | private $_validator; |
||
77 | |||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 41 | public function init() |
|
89 | |||
90 | /** |
||
91 | * Returns the validator declared in [[rule]]. |
||
92 | * @param Model|null $model model in which context validator should be created. |
||
93 | * @return Validator the declared validator. |
||
94 | */ |
||
95 | 9 | private function getValidator($model = null) |
|
103 | |||
104 | /** |
||
105 | * Creates validator object based on the validation rule specified in [[rule]]. |
||
106 | * @param Model|null $model model in which context validator should be created. |
||
107 | * @throws \yii\base\InvalidConfigException |
||
108 | * @return Validator validator instance |
||
109 | */ |
||
110 | 9 | private function createEmbeddedValidator($model) |
|
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | 7 | public function validateAttribute($model, $attribute) |
|
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | 4 | protected function validateValue($value) |
|
197 | } |
||
198 |