@param Validator $validator
@param mixed $object

@param $forScenario

@return bool
1362
public function validate(Validator $validator, $object, $forScenario)
    {
        if (!is_array($object) && !$object instanceof \Traversable) {
            return false;
        }

        foreach ($object as $v) {
            if(!$this->rule->validate($validator, $v, $forScenario)) {
                return false;
            }
        }

        return true;
    }
314791
protected function hasValidator(Validator $validator) : bool
    {
        $hash = spl_object_hash($validator);

        return isset($this->validators[$hash]);
    }
973732
public function validate($validator)
    {
        parent::validate($validator);

        // Don't validate empty fields
        if (empty($this->value)) {
            return true;
        }

        // Use the VideoLink object to validate
        $obj = VideoLink::create()->setValue($this->value);

        if (!$obj->getService()) {
            $validator->validationError(
                $this->name,
                _t(__CLASS__ . '.ValidationError', 'Please enter a valid YouTube or Vimeo link'),
                'validation'
            );
            return false;
        }

        return true;
    }
1247952
protected function getApplicableRules($forScenario)
    {
        if (!isset($this->rules[ $forScenario ])) {
            //fall back to 'all'
            $forScenario = Validator::SCENARIO_ALL;
        }

        return $this->rules[ $forScenario ];
    }
406577
public function validator($validator, $condition = true)
    {
        if (!$condition) {
            return $this;
        }

        if ($validator instanceof \Closure) {
            $this->validators[] = $validator;
        } else {
            $this->rule($validator);
        }

        return $this;
    }
708693
public function attachValidators(Validator $validator)
    {
        /** @var ClassMetadata $fileMetadata */
        $fileMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\FileDescriptor');
        /** @var ClassMetadata $constantMetadata */
        $constantMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\ConstantDescriptor');
        /** @var ClassMetadata $functionMetadata */
        $functionMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\FunctionDescriptor');
        /** @var ClassMetadata $classMetadata */
        $classMetadata     = $validator->getMetadataFor('phpDocumentor\Descriptor\ClassDescriptor');
        /** @var ClassMetadata $interfaceMetadata */
        $interfaceMetadata = $validator->getMetadataFor('phpDocumentor\Descriptor\InterfaceDescriptor');
        /** @var ClassMetadata $traitMetadata */
        $traitMetadata     = $validator->getMetadataFor('phpDocumentor\Descriptor\TraitDescriptor');
        /** @var ClassMetadata $propertyMetadata */
        $propertyMetadata  = $validator->getMetadataFor('phpDocumentor\Descriptor\PropertyDescriptor');
        /** @var ClassMetadata $methodMetadata */
        $methodMetadata    = $validator->getMetadataFor('phpDocumentor\Descriptor\MethodDescriptor');

        $fileMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50000')));
        $classMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50005')));
        $propertyMetadata->addConstraint(new phpDocAssert\Property\HasSummary());
        $methodMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50008')));
        $interfaceMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50009')));
        $traitMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50010')));
        $functionMetadata->addPropertyConstraint('summary', new Assert\NotBlank(array('message' => 'PPC:ERR-50011')));

        $functionMetadata->addConstraint(new phpDocAssert\Functions\IsReturnTypeNotAnIdeDefault());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\IsReturnTypeNotAnIdeDefault());

        $functionMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\IsParamTypeNotAnIdeDefault());
        $functionMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());
        $methodMetadata->addConstraint(new phpDocAssert\Functions\AreAllArgumentsValid());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasSinglePackage());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasSingleSubpackage());

        $classMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $interfaceMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $traitMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());
        $fileMetadata->addConstraint(new phpDocAssert\Classes\HasPackageWithSubpackage());

        return $validator;
    }
739108
public function addValidator(Validator $validator) : Component
    {
        $hash = spl_object_hash($validator);
        $this->validators[$hash] = $validator;

        return $this;
    }
21154
public function validate($validator)
    {
        // Validate currency
        $currencies = $this->getAllowedCurrencies();
        $currency = $this->fieldCurrency->dataValue();
        if ($currency && $currencies && !in_array($currency, $currencies)) {
            $validator->validationError(
                $this->getName(),
                _t(
                    __CLASS__ . '.INVALID_CURRENCY',
                    'Currency {currency} is not in the list of allowed currencies',
                    ['currency' => $currency]
                )
            );
            return false;
        }

        // Field-specific validation
        return $this->fieldAmount->validate($validator) && $this->fieldCurrency->validate($validator);
    }
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;
    }
621116
public function validate(Validator $validator, $object, $forScenario)
    {
        if (!is_string($object)) {
            return false;
        }

        $length = strlen($object);
        if ($this->minLength !== null) {
            if ($length < $this->minLength) {
                return false;
            }
        }
        if ($this->maxLength !== null) {
            if ($length > $this->maxLength) {
                return false;
            }
        }

        return true;
    }
499960
protected function useValidator(Validator $validator)
    {
        if ($validator !== $this->validator9) {
            return true;

        }
        $set1 = substr($this->account, 0, 2);
        $set2 = substr($this->account, 0, 3);
        return ($set1 >= 51  && $set1 <= 59)
            || ($set2 >= 901 && $set2 <= 910);
    }
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'));
            }
        });
    }
1333893
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->add('email', 'valid', ['rule' => 'email'])
            ->allowEmpty('email');

        $validator
            ->allowEmpty('password');

        $validator
            ->add('active', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('active');

        $validator
            ->allowEmpty('usercode');

        $validator
            ->allowEmpty('new_password');


        $validator
            ->allowEmpty('confirm_password');

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

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

        return $validator;
    }
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;
	}
1092642
public function addValidator(Validator $validator) : ValidationCheckerInterface
    {
        $this->validated = false;
        $validator->setValidationSet($this);
        array_push($this->validators, $validator);
        return $this;
    }
39694
public function addValidator(ValidatorInterface $validator)
    {
        if ($validator instanceof tao_helpers_form_validators_NotEmpty) {
            $this->addAttribute('required', true);
        }
        $this->validators[] = $validator;
    }
925890
public function setValidator($validator)
    {
        if (!($validator instanceof AnDomainValidatorAbstract)) {
            if (is_string($validator) && strpos($validator, '.') === false) {
                $identifier = clone $this->getIdentifier();
                $identifier->path = array('domain','validator');
                $identifier->name = $validator;
            } else {
                $identifier = $this->getIdentifier($validator);
            }

            register_default(array('identifier' => $identifier, 'prefix' => $this->_repository->getClone()));

            $validator = $identifier;
        }

        $this->_validator = $validator;

        return $this;
    }