MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / getActiveValidators

Method getActiveValidators

benches/fixtures/yii/Model.php:432–453  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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()]].

Callers 2

validateMethod · 0.95
isAttributeRequiredMethod · 0.95

Calls 4

activeAttributesMethod · 0.95
getScenarioMethod · 0.95
getValidatorsMethod · 0.95
isActiveMethod · 0.80

Tested by

no test coverage detected