* Returns the validators applicable to the current [[scenario]]. * @param string $attribute the name of the attribute whose applicable validators should be returned. * If this is null, the validators for ALL attributes in the model will be returned. * @return \yii\validators\Validator[] the validators applicable to the current [[scenario]]. */
($attribute = null)
| 430 | * @return \yii\validators\Validator[] the validators applicable to the current [[scenario]]. |
| 431 | */ |
| 432 | public function getActiveValidators($attribute = null) |
| 433 | { |
| 434 | $activeAttributes = $this->activeAttributes(); |
| 435 | if ($attribute !== null && !in_array($attribute, $activeAttributes, true)) { |
| 436 | return []; |
| 437 | } |
| 438 | $scenario = $this->getScenario(); |
| 439 | $validators = []; |
| 440 | foreach ($this->getValidators() as $validator) { |
| 441 | if ($attribute === null) { |
| 442 | $validatorAttributes = $validator->getValidationAttributes($activeAttributes); |
| 443 | $attributeValid = !empty($validatorAttributes); |
| 444 | } else { |
| 445 | $attributeValid = in_array($attribute, $validator->getValidationAttributes($attribute), true); |
| 446 | } |
| 447 | if ($attributeValid && $validator->isActive($scenario)) { |
| 448 | $validators[] = $validator; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return $validators; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Creates validator objects based on the validation rules specified in [[rules()]]. |
no test coverage detected