Get any custom message from the validator or return a default message.

@param \Illuminate\Validation\Validator $validator
@param string $rule
@param string $name
@param string $locale

@return string
425501
protected function getMessage($validator, $rule, $name, $locale)
    {
        $keys = [
            "{$name}.{$rule}",
            "{$name}.*.{$rule}",
            "{$name}.{$locale}.{$rule}",
        ];

        foreach ($keys as $key) {
            if (array_key_exists($key, $validator->customMessages)) {
                return $validator->customMessages[$key];
            }
        }

        return trans('validation.unique');
    }
292661
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('login', 'create')
            ->notEmpty('login', __d('community', 'Login could not be empty.'))
            ->add('login', 'unique', [
                'provider' => 'table',
                'rule'     => 'validateUnique',
                'message'  => __d('community', 'User with this login already exists.')
            ])
            ->add('login', 'length', [
                'rule'    => ['minLength', MIN_LENGTH_LOGIN],
                'message' => __d('community', 'The minimum login length must be {0} characters', MIN_LENGTH_LOGIN)
            ]);

        $validator
            ->requirePresence('slug', 'create')
            ->notEmpty('slug', __d('community', 'Alias could not be empty.'))
            ->add('slug', 'unique', [
                'provider' => 'table',
                'rule'     => 'validateUnique',
                'message'  => __d('community', 'User with this alias already exists.')
            ])
            ->add('slug', 'length', [
                'rule'    => ['minLength', MIN_LENGTH_LOGIN],
                'message' => __d('community', 'The minimum alias length must be {0} characters', MIN_LENGTH_LOGIN)
            ]);

        $validator
            ->requirePresence('group_id', 'create')
            ->notEmpty('group_id', __d('community', 'Please, choose user group.'))
            ->notEmpty('name', __d('community', 'Please, enter you full name.'));

        $validator
            ->notEmpty('email', __d('community', 'Please, enter you email.'))
            ->add('email', 'unique', [
                'provider' => 'table',
                'rule'     => 'validateUnique',
                'message'  => __d('community', 'User with this email already exists.')
            ])
            ->add('email', 'valid', [
                'rule'    => 'email',
                'message' => __d('community', 'Please enter valid email.')
            ]);

        $validator
            ->notEmpty('password', __d('community', 'Please, enter you password.'))
            ->add('password', 'minLength', [
                'rule'    => ['minLength', MIN_LENGTH_PASS],
                'message' => __d('community', 'The minimum password length is {0}', MIN_LENGTH_PASS)
            ]);

        $validator
            ->notEmpty('password_confirm', __d('community', 'Please, confirm you password.'))
            ->add('password_confirm', 'no-misspelling', [
                'rule'    => ['compareWith', 'password'],
                'message' => __d('community', 'Passwords are not equal')
            ]);

        return $validator;
    }
699514
private function parseRule($rule)
	{
		if (!is_array($rule) || (count($rule) < 2)) {
			throw new ValidatorException('Invalid declaration of validation rule');
		}

		is_array($rule[0]) || $rule[0] = [$rule[0]];

		if (!is_string($rule[1])) {
			throw new ValidatorException('Validator name: Expected string');
		}

		if (isset($rule[2])) {
			if(!is_array($rule[2])) {
				throw new ValidatorException('Validator options: Expected array');
			}
		} else {
			$rule[2] = [];
		}
		$rule[2] = new ArrayWrapper($rule[2]);

		return $rule;
	}
634905
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('source');

        $validator
            ->dateTime('trashed')
            ->allowEmpty('trashed');

        return $validator;
    }
953309
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->notEmpty('name', __d('user', 'You must provide a name.'))
            ->requirePresence('username', 'create')
            ->add('username', [
                'characters' => [
                    'rule' => function ($value, $context) {
                        return preg_match('/^[a-zA-Z0-9\_]{3,}$/', $value) === 1;
                    },
                    'provider' => 'table',
                    'message' => __d('user', 'Invalid username. Only letters, numbers and "_" symbol, and at least three characters long.'),
                ],
            ])
            ->requirePresence('email')
            ->notEmpty('email', __d('user', 'e-mail cannot be empty.'))
            ->requirePresence('password', 'create')
            ->allowEmpty('password', 'update')
            ->add('password', [
                'compare' => [
                    'rule' => function ($value, $context) {
                        $value2 = isset($context['data']['password2']) ? $context['data']['password2'] : false;

                        return (new DefaultPasswordHasher)->check($value2, $value) || $value == $value2;
                    },
                    'message' => __d('user', 'Password mismatch.'),
                ]
            ])
            ->allowEmpty('web')
            ->add('web', 'validUrl', [
                'rule' => 'url',
                'message' => __d('user', 'Invalid URL.'),
            ]);

        return $this->_applyPasswordPolicies($validator);
    }
674170
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create')
            ->add('email', 'valid', ['rule' => 'email'])
            ->requirePresence('email', 'create')
            ->notEmpty('email')
            ->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table'])
            ->notEmpty('password');

        $validator->add('new_password', 'custom', [
            'rule' => function ($value, $context) {
                if ($value !== $context['data']['confirm_password']) {
                    return false;
                }
                return true;
            },
            'message' => __('Passwords are not equal!'),
        ]);

        $validator->add('confirm_password', 'custom', [
            'rule' => function ($value, $context) {
                if ($value !== $context['data']['new_password']) {
                    return false;
                }
                return true;
            },
            'message' => __('Passwords are not equal.'),
        ]);


        return $validator;
    }
787856
protected function getValidatorInstance($rules, $data, $model=null)
    {
        $factory = $this->container->make('Illuminate\Validation\Factory');

        if (method_exists($this, 'validatorInstance'))
        {
            return $this->container->call(
                [$this, 'validatorInstance'],
                compact('factory')
            );
        }

        return $factory->make(
            $data, $rules, $this->customMessages(), $this->customAttributes()
        );
    }
836055
public function getValidationMessage($attribute, $rule, $data = [], $type = null)
    {
        $path = Str::snake($rule);
        if ($type !== null) {
            $path .= '.' . $type;
        }

        if ($this->translator->has('validation.custom.' . $attribute . '.' . $path)) {
            $path = 'custom.' . $attribute . '.' . $path;
        }

        $niceName = $this->getValidationAttribute($attribute);

        return $this->translator->get('validation.' . $path, $data + ['attribute' => $niceName]);
    }
27584
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('uid', 'create');

        $validator
            ->requirePresence('username', 'create')
            ->notEmpty('username');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        $validator
            ->requirePresence('role', 'create')
            ->notEmpty('role')
            ->add('role', 'inList', [
                'rule' => ['inList', ['admin', 'author']],
                'message' => 'Please enter a valid role'
            ]);

        $validator
            ->boolean('verified')
            ->requirePresence('verified', 'create')
            ->notEmpty('verified');

        $validator
            ->email('email')
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        return $validator;
    }
228936
protected function AddValidator($name, Validator $validator, $errorPrefix = '')
    {
        $field = $this->GetElement($name);
        if (!$errorPrefix)
        {
            $errorPrefix = $this->ErrorPrefix($name);
        }
        $validator->SetErrorLabelPrefix($errorPrefix);
        $field->AddValidator($validator);
    }
1073748
public static function parseRule($validatorType, $rule)
    {
        $className = \get_class($validatorType);

        if (empty(self::$rules[$className])) {
            self::buildRules($validatorType, $className);
        }

        $ruleName   = \explode(":", $rule);
        $methodName = self::getMethodName($className, $ruleName[0]);

        $arguments = \substr($rule, \strlen($ruleName[0]) + 1, \strlen($rule));
        $arguments = \explode(":", $arguments);
        $arguments = self::convertStringBooleanToBoolean($arguments);

        return [$methodName, $arguments];
    }
129545
private static function applyValidatorRules($validator, array &$rules)
    {
        $validatorRule = ValidatorRule::getInstance();
        foreach ($rules as $rule) {
            list($functionName, $arguments) = $validatorRule->parseRule($validator, $rule);
            $validator = \call_user_func_array([$validator, $functionName], $arguments);
        }

        return $validator;
    }
200566
protected function getMessage( $attribute, $rule, array $parameters )
	{
		if( in_array( $rule, $this->sizeRules )) {
			return $this->getSizeMessage( $attribute, $rule, $parameters );
		}

		$lowerRule = $this->snakeCase( $rule );

		return $this->translator( $lowerRule, $rule, $attribute, $parameters );
	}
166856
public function get_error_message($field, $value, $validator) {
		return $validator->get_label($field) . ' must match ' . $validator->get_label($this->compare_against);
	}
1258530
protected function getErrorMessage(RuleInterface $rule, string $field, object $parsedRule): string
	{
		$field = $this->getOriginalFieldName($field);

		if($this->i18n !== null && $rule instanceof I18nAwareInterface)
		{
			return $rule->setI18n($this->i18n)->getTranslatedErrorMessage($field, $parsedRule->name, $parsedRule->package);
		}

		return $rule->getErrorMessage($field);
	}
1284347
private function createEachRule($rule, $validator = null)
    {
        unset($rule['attributes']);
        if (isset($rule['validator'])) {
            array_unshift($rule, "'{$rule['validator']}'");
            unset($rule['validator']);
        } elseif ($validator !== null) {
            array_unshift($rule, "'$validator'");
        }
        $result = [
            'validator' => 'each',
            'rule' => $rule,
            'attributes' => [],
        ];
        foreach (['on', 'except'] as $param) {
            if (isset($rule[$param])) {
                $result[$param] = $result['rule'][$param];
                unset($result['rule'][$param]);
            }
        }
        return $result;
    }
848019
public static function getValidator($name, $options = array())
    {
        $returnValue = null;

        
		
		$clazz = 'tao_helpers_form_validators_'.$name;
		if(class_exists($clazz)){
			$returnValue = new $clazz($options);
		} else {
			common_Logger::w('Unknown validator '.$name, array('TAO', 'FORM'));
		}
		
        

        return $returnValue;
    }