Example #1
0
 /**
  * Validates an attribute.
  *
  * @param string $attribute
  * @param array $validators
  * @param Context $context
  */
 protected function validate_attribute($attribute, array $validators, Context $context)
 {
     foreach ($validators as $class_or_alias => $validator_params) {
         $context->value = $value = $context->value($attribute);
         $context->validator = $validator = $this->create_validator($class_or_alias);
         $context->validator_params = $validator->normalize_params($validator_params);
         $context->message = $validator::DEFAULT_MESSAGE;
         $context->message_args = [Validator::MESSAGE_ARG_ATTRIBUTE => $attribute, Validator::MESSAGE_ARG_VALUE => $value, Validator::MESSAGE_ARG_VALIDATOR => get_class($validator)];
         if ($this->should_skip($context)) {
             return;
         }
         if (!$validator->validate($value, $context)) {
             $this->error($context);
         }
         if ($this->should_stop($context)) {
             break;
         }
     }
 }