Prepare the validator.
@param  \Asgard\Validation\ValidatorInterface $validator
@param  array                                 $locales
@return \Asgard\Validation\ValidatorInterface
829
public function prepareValidator(\Asgard\Validation\ValidatorInterface $validator, array $locales=[]) {
		$this->getDefinition()->trigger('validation', [$this, $validator], function($chain, $entity, $validator) use($locales) {
			$messages = [];

			foreach($this->getDefinition()->properties() as $name=>$property) {
				if($locales && $property->get('i18n')) {
					foreach($locales as $locale) {
						if($property->get('many')) {
							if($this->get($name, null, false) instanceof ManyCollection) {
								foreach($this->get($name, null, false) as $k=>$v) {
									$propValidator = $validator->attribute($name.'.'.$locale.'.'.$k);
									$property->prepareValidator($propValidator);
									$propValidator->formatParameters(function(&$params) use($name) {
										$params['attribute'] = $name;
									});
									$propValidator->ruleMessages($property->getMessages());
								}
							}
						}
						else {
							$propValidator = $validator->attribute($name.'.'.$locale);
							$property->prepareValidator($propValidator);
							$propValidator->formatParameters(function(&$params) use($name) {
								$params['attribute'] = $name;
							});
							$propValidator->ruleMessages($property->getMessages());
						}
					}
				}
				else {
					if($property->get('many')) {
						if($this->get($name, null, false) instanceof ManyCollection) {
							foreach($this->get($name, null, false) as $k=>$v) {
								$propValidator = $validator->attribute($name.'.'.$k);
								$property->prepareValidator($propValidator);
								$propValidator->formatParameters(function(&$params) use($name) {
									$params['attribute'] = $name;
								});
								$propValidator->ruleMessages($property->getMessages());
							}
						}
					}
					else {
						$propValidator = $validator->attribute($name);
						$property->prepareValidator($propValidator);
						$propValidator->ruleMessages($property->getMessages());
					}
				}
			}

			$messages = array_merge($messages, $this->getDefinition()->messages());
			$validator->attributesMessages($messages);

			$validator->set('entity', $this);
		});

		return $validator;
	}
596813
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('address', 'create')
			->notEmpty('address')
			->add('address', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);

		$validator
			->allowEmpty('formatted_address');

		$validator
			->allowEmpty('country');

		$validator
			->decimal('lat')
			->allowEmpty('lat');

		$validator
			->decimal('lng')
			->allowEmpty('lng');

		$validator
			->allowEmpty('data');

		return $validator;
	}
1266750
public function addValidation(Validator $validator) {
		$fields = (array)$this->getConfig('dummyField');
		foreach ($fields as $field) {
			$validator->requirePresence($field);
			$validator->allowEmpty($field);
			$validator->add($field, [
				$field => [
					'rule' => function ($value, $context) {
						return $value === '';
					},
					'last' => true
				],
			]);
		}
	}
743172
public function createService(ServiceLocatorInterface $validators)
    {
        /* @var $options InputFilterOptionsInterface */
        $options = $validators->getServiceLocator()->get(ModuleOptions::class);

        $chain = new ValidatorChain;

        $chain->attachByName('StringLength', [
            'min' => $options->getMinIdentityLength(),
            'max' => $options->getMaxIdentityLength(),
        ], true);

        if ($options->getIdentityRegexPattern()) {
            $chain->attachByName('Regex', [
                'messages' => [
                    Regex::NOT_MATCH => 'Incorrect identity. ' .
                        'Identity must contain alphanumeric characters without spaces',
                ],
                'pattern' => $options->getIdentityRegexPattern(),
            ], true);
        }

        return $chain;
    }
170271
public function validate($validator)
    {
        // get the previous values (could contain comma-delimited list)

        $previous = $value = $this->Value();

        if (is_string($value) && strstr($value, ",")) {
            $value = explode(",", $value);
        }

        // set the value as an array for parent validation

        $this->setValue($value);

        $validated = parent::validate($validator);

        // restore previous value after validation

        $this->setValue($previous);

        return $validated;
    }
305522
protected function validate($validator)
    {
        $validator->validatePresence('operation');
        $validator->validatePresence('mode');
        $validator->validatePresence('payment.currency_code');
        $validator->validatePresence('payment.amount_total');
        $validator->validatePresence('payment.merchant_payment_code');
        $validator->validatePresence('payment.name');
        $validator->validatePresence('payment.email');
        $validator->validatePresence('payment.payment_type_code');

        // Gambiarration
        $this->params['integration_key'] = \Ebanx\Config::getIntegrationKey();
        $this->params = array('request_body' => json_encode($this->params));
    }
946607
public function addValidators(array $validators)
    {
        foreach ($validators as $validator) {
            if ($validator === null) {
                continue;
            }

            $this->addValidator($validator);
        }

        return $this;
    }
871997
public function validate(ValidatorInterface $validator) {
        $validator->validate($this->getEntity());
        $messages = $validator->getMessages();
        if(is_array($messages)) {
            foreach($messages as $message) {
                $this->getEntity()->appendMessage($message);
            }
        }
    }
994877
public function addValidator($validator)
    {
        if (!($validator instanceof \Pop\Validator\AbstractValidator) && !is_callable($validator)) {
            throw new Exception('Error: The validator must be an instance of Pop\Validator\AbstractValidator or a callable object.');
        }
        $this->validators[] = $validator;
        return $this;
    }
322219
public function validate(Validator $validator = null)
    {
        if (null === $validator) {
            $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
        }

        $failureMap = new ConstraintViolationList();

        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;


            $retval = $validator->validate($this);
            if (count($retval) > 0) {
                $failureMap->addAll($retval);
            }

            if (null !== $this->collAttributeAttributeTypes) {
                foreach ($this->collAttributeAttributeTypes as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }
            if (null !== $this->collAttributeTypeI18ns) {
                foreach ($this->collAttributeTypeI18ns as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }

            $this->alreadyInValidation = false;
        }

        $this->validationFailures = $failureMap;

        return (Boolean) (!(count($this->validationFailures) > 0));

    }
217877
public function validator(callable $validator, string ...$types): BuilderInterface
    {
        $this->resolver->validator($validator, ...$types);

        return $this;
    }
560445
public function addValidators(Validator\ValidatorInterface ...$validators) {
        foreach($validators as $validator) {
            $this->addValidator($validator);
        }
        return $this;
    }
617542
public function withValidator(string $name, ValidatorInterface $validator): Form
    {
        if (! isset($this->validators[$name])) {
            $this->validators[$name] = [];
        }

        $this->validators[$name][] = $validator;

        return $this;
    }
461502
public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmpty('email', __d('wasabi_core', 'Please enter an email address.'))
            ->add('email', [
                'email' => [
                    'rule' => 'email',
                    'message' => __d('wasabi_core', 'Please enter a valid email address.')
                ]
            ])
            ->notEmpty('password', __d('wasabi_core', 'Please enter a password.'), 'create')
            ->add('password', [
                'length' => [
                    'rule' => ['minLength', 6],
                    'message' => __d('wasabi_core', 'Ensure your password consists of at least 6 characters.')
                ]
            ])
            ->notEmpty('password_confirmation', __d('wasabi_core', 'Please repeat your Password.'), function ($context) {
                if ($context['newRecord'] === true) {
                    return true;
                }
                if (isset($context['data']['password']) && !empty($context['data']['password'])) {
                    return true;
                }
                return false;
            })
            ->add('password_confirmation', 'equalsPassword', [
                'rule' => function ($passwordConfirmation, $provider) {
                    if ($passwordConfirmation !== $provider['data']['password']) {
                        return __d('wasabi_core', 'The Password Confirmation does not match the Password field.');
                    }
                    return true;
                }
            ])
            ->add('language_id', 'isValid', [
                'rule' => function ($languageId) {
                    $languageIds = Hash::map(Configure::read('languages.backend'), '{n}', function ($language) {
                        return $language->id;
                    });
                    if (!in_array($languageId, $languageIds)) {
                        return __d('wasabi_core', 'Invalid language selected.');
                    }
                    return true;
                }
            ])
            ->add('groups', 'notEmpty', [
                'rule' => function ($groups) {
                    return !empty($groups['_ids'] ?? []);
                },
                'message' => __d('wasabi_core', 'Please select a group this user should belong to.')
            ])
            ->add('groups', 'isValid', [
                'rule' => function ($groups) {
                    if (empty($groups['_ids'])) {
                        return true;
                    }
                    $validGroupIds = $this->Groups->find()->extract('id')->toArray();
                    foreach ($groups['_ids'] as $groupId) {
                        if (!in_array($groupId, $validGroupIds)) {
                            return false;
                        }
                    }
                    return true;
                },
                'message' => __d('wasabi_core', 'Please select a group from the provided list.')
            ]);

        if (Wasabi::setting('Core.User.has_username')) {
            $validator->notEmpty('username', __d('wasabi_core', 'Please enter a username.'));
        }

        if (Wasabi::setting('Core.User.has_firstname_lastname')) {
            $validator->notEmpty('firstname', __d('wasabi_core', 'Please enter a first name.'));
            $validator->notEmpty('lastname', __d('wasabi_core', 'Please enter a last name.'));
        }

        if (Wasabi::setting('Core.User.allow_timezone_change')) {
            $validator->notEmpty('timezone', __d('wasabi_core', 'Please choose a time zone.'));
            $validator->add('timezone', 'isValid', [
                'rule' => function ($timezone) {
                    if (!in_array($timezone, DateTimeZone::listIdentifiers())) {
                        return __d('wasabi_core', 'Invalid timezone selected.');
                    }
                    return true;
                }
            ]);
        }

        return $validator;
    }
186504
public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            if ($duplicate = File::whereChecksum($this->input('checksum'))->first()) {
                $validator->errors()->add('checksum', sprintf(
                    __('msg.already_exists'), $duplicate->url, $duplicate->title
                ));
            }
        });

        return $validator;
    }
1138976
public function setValidator($validator)
    {
        $this->clearCache();
        $this->validators = [];
        $this->addValidator($validator);

        return $this;
    }
489822
public function validateSettings(array $settings, Validator $validator)
    {
        $handler = $this->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->validateSettings($this, $settings, $validator);
        }
    }