Add error messages to the validator.

@param \Illuminate\Validation\Validator $validator
@param array $parameters
@param string $name
@param string $locale

@return void
979110
protected function addErrorsToValidator($validator, $parameters, $name, $locale)
    {
        $rule = 'unique_translation';
        $message = $this->getFormattedMessage($validator, $rule, $parameters, $name, $locale);

        $validator->errors()
            ->add($name, $message)
            ->add("{$name}.{$locale}", $message);
    }
1260119
public function addValidator($validator)
    {
        if (!$validator instanceof ValidatorInterface) {
            if (!is_callable($validator)) {
                throw new \InvalidArgumentException('Validator should be callable or ValidatorInterface.');
            }

            $validator = new CallbackValidator($validator);
        }

        $this->validators[] = $validator;

        return $this;
    }
77745
protected function addError( $attribute, $rule, array $parameters )
	{
		$message = $this->getMessage( $attribute, $rule, $parameters );

		$this->errors[ $attribute ]['errors'][] = $message;

		if( !isset( $this->errors[ $attribute ]['value'] )) {
			$this->errors[ $attribute ]['value'] = $this->getValue( $attribute );
		}
	}
615650
public function prepareValidator(\Asgard\Validation\ValidatorInterface $validator) {
		if(isset($this->params['validation'])) {
			$validation = $this->params['validation'];
			foreach($validation as $name=>$params) {
				if(is_integer($name)) {
					$name = $params;
					$params = [];
				}
				if($name === 'required')
					$name = 'ormrequired';
				$validator->rule($name, $params);
			}
		}
	}
365749
protected function _setValidator($validator)
    {
        if (!is_null($validator) && !($validator instanceof ValidatorInterface)) {
            throw $this->_createInvalidArgumentException($this->__('Invalid validator'), null, null, $validator);
        }

        $this->validator = $validator;
    }
1280079
public void validateParameters() {

        // localisation
        CmsMessages messages = Messages.get().getBundle(getLocale());

        StringBuffer validationErrors = new StringBuffer();
        if (CmsStringUtil.isEmpty(getParamResource())) {
            validationErrors.append(messages.key(Messages.GUI_ELEM_RENAME_VALIDATE_RESOURCE_FOLDER_0)).append("<br>");
        }
        if (CmsStringUtil.isEmpty(getParamTemplate())) {
            validationErrors.append(messages.key(Messages.GUI_ELEM_RENAME_VALIDATE_SELECT_TEMPLATE_0)).append("<br>");
        }
        if (CmsStringUtil.isEmpty(getParamLocale())) {
            validationErrors.append(messages.key(Messages.GUI_ELEM_RENAME_VALIDATE_SELECT_LANGUAGE_0)).append("<br>");
        }
        if (CmsStringUtil.isEmpty(getParamOldElement())) {
            validationErrors.append(messages.key(Messages.GUI_ELEM_RENAME_VALIDATE_ENTER_OLD_ELEM_0)).append("<br>");
        }
        if (CmsStringUtil.isEmpty(getParamNewElement())) {
            validationErrors.append(messages.key(Messages.GUI_ELEM_RENAME_VALIDATE_ENTER_NEW_ELEM_0)).append("<br>");
        }
        if (!isValidElement(getParamNewElement())) {
            validationErrors.append(
                messages.key(
                    Messages.GUI_ELEM_RENAME_VALIDATE_INVALID_NEW_ELEM_2,
                    getParamNewElement(),
                    getParamTemplate())).append("<br>");
        }

        setErrorMessage(validationErrors.toString());
    }
666501
private function validate(string $name, $value): bool
    {
        if (! isset($this->validators[$name])) {
            return true;
        }

        $errors = [];

        $isValid = true;
        foreach ($this->validators[$name] as $validator) {
            if (! $validator->is_valid($value)) {
                $errors = array_merge($errors, $validator->get_error_messages());
                $isValid = false;
            }
        }

        $element = $this->element($name);
        if ($element instanceof ErrorAwareInterface) {
            $element->withErrors($errors);
        }

        return $isValid;
    }
73286
protected function registerValidationRules($validator)
    {
        /**
         * elfinder validator
         */
        $validator->resolver(function($translator, $data, $rules, $messages)
        {
            return new BaseValidator($translator, $data, $rules, $messages);
        });
        $validator->replacer('elfinder_max', function($message, $attribute, $rule, $parameters) {
            return str_replace(':size',$parameters[0],$message);
        });
        $validator->replacer('elfinder', function($message, $attribute, $rule, $parameters) {
            return str_replace(':values',implode(', ', $parameters),$message);
        });

    }
161624
public function addValidator($validator)
    {
        if (!($validator instanceof ValidatorInterface) && !is_callable($validator)) {
            $validator = ValidatorHelper::create($validator);
        }

        $this->validator->addValidator($validator);

        return $this;
    }
1293348
public function withValidator($validator): void
    {
        $validator->after(function ($validator) {
            if (! auth()->guard($this->route('guard'))->getProvider()->validateCredentials($this->user($this->route('guard')), ['password' => $this->get('old_password')])) {
                $validator->errors()->add('old_password', trans('cortex/auth::messages.account.wrong_password'));
            }

            if (auth()->guard($this->route('guard'))->getProvider()->validateCredentials($this->user($this->route('guard')), ['password' => $this->get('new_password')])) {
                $validator->errors()->add('new_password', trans('cortex/auth::messages.account.different_password'));
            }
        });
    }
591441
protected function addExtensions(Validator $validator)
    {
        $validator->addExtensions($this->extensions);

        // Next, we will add the implicit extensions, which are similar to the required
        // and accepted rule in that they are run even if the attributes is not in a
        // array of data that is given to a validator instances via instantiation.
        $validator->addImplicitExtensions($this->implicitExtensions);

        $validator->addDependentExtensions($this->dependentExtensions);

        $validator->addReplacers($this->replacers);

        $validator->setFallbackMessages($this->fallbackMessages);
    }
27562
protected function throwValidationException(Request $request, $validator)
    {
        throw new ResourceException($validator->errors()->first(), $validator->errors());
//        throw new ValidationException($validator, $this->buildFailedValidationResponse(
//            $request, $this->formatValidationErrors($validator)
//        ));
    }
1160558
private function loadValidatorLoader(string $entityManagerName, ContainerBuilder $container) : void
    {
        if (! interface_exists(LoaderInterface::class) || ! class_exists(DoctrineLoader::class)) {
            return;
        }

        $validatorLoaderDefinition = $container->register(sprintf('doctrine.orm.%s_entity_manager.validator_loader', $entityManagerName), DoctrineLoader::class);
        $validatorLoaderDefinition->addArgument(new Reference(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName)));

        $validatorLoaderDefinition->addTag('validator.auto_mapper', ['priority' => -100]);
    }
1153633
protected function validate(array $attributes, string $name, array $parameters): bool
    {
        if (! is_null($attributes[$name])) {
            return true;
        }

        $this->addError($name, $parameters, '%s 不能为 Null');

        return false;
    }
1369061
public function prepareValidator(\Asgard\Validation\ValidatorInterface $validator) {
		if($this->get('required'))
			$validator->rule('required', true);
		if($this->get('length'))
			$validator->rule('maxlength', $this->get('length'));
		if($this->get('in'))
			$validator->rule('in', [array_keys($this->get('in'))]);

		if(method_exists($this, '_prepareValidator'))
			$this->_prepareValidator($validator);

		$rules = isset($this->params['validation']) ? $this->params['validation']:[];
		if(!is_array($rules))
			$rules = [$rules];
		$validator->rules($rules);
	}
42165
public function validate(array $input, AppliesToResource $resource=null, $locale=null)
    {

        // If a generic validator didnt have a resource until here, assign it
        if (!$this->rules && $this instanceof GenericValidatorContract && !$this->resource()) {
            $this->setResource($resource);
        }

        $rules = $this->prepareRulesForValidation($this->rules(), $input, $resource, $locale);

        $this->callBeforeListeners('validate', [$input, $rules, $resource, $locale]);

        $validation = $this->performValidation($input, $rules, $resource, $locale);

        $this->callAfterListeners('validate', [$input, $rules, $resource, $validation, $locale]);

        if (count($validation)) {
            throw $validation;
        }

        return true;
    }
8318
protected function _validate($value, $name, $parameters)
    {
        if (is_object($value)) {
            return $value;
        }

        $method = "_validate_$name";
        if (method_exists($this, $method)) {
            return $parameters === null ? $this->$method($value) : $this->$method($value, $parameters);
        }

        if (function_exists($name)) {
            return $parameters === null ? $name($value) : $name($value, $parameters);
        }

        throw new NotSupportedException(['unsupported `:validate` validate method', 'validate' => $name]);
    }