Default validation rules.

@param \Cake\Validation\Validator $validator Validator instance.
@return \Cake\Validation\Validator
433689
public function validationDefault(Validator $validator): \Cake\Validation\Validator
    {
        $validator->add('data', 'custom', [
            'rule' => function ($value, $context) {
                if ($context['data']['action'] != ModelHistory::ACTION_COMMENT) {
                    return true;
                }

                return !empty($value['comment']);
            },
            'message' => __d('model_history', 'comment_empty')
        ]);

        return $validator;
    }
104671
public function setValidationRules(Validator $validator, array $options = []) : Validator
    {
        $options = array_merge($this->defaultOptions, $this->fixOptions($options));

        $provider = $this->config->getProvider('validationRules');
        $validator = (new $provider($this->config))->provide($validator, $options);
        if (! $validator instanceof Validator) {
            throw new RuntimeException(
                sprintf('Provider returned value must be an instance of %s.', Validator::class)
            );
        }

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

        if (!filter_var($this->value, FILTER_VALIDATE_URL)) {
            if (filter_var('http://' . $this->value, FILTER_VALIDATE_URL)) {
                $this->value = 'http://' . $this->value;
            } else {
                $validator->validationError(
                    $this->name,
                    _t(__CLASS__ . '.ValidationError', 'Please enter a valid URL including the http:// or https://'),
                    'validation'
                );
                return false;
            }
        }

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

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

        $validator
            ->email('email')
            ->allowEmpty('email');

        $validator
            ->allowEmpty('username');

        $validator
            ->allowEmpty('password');

        $validator
            ->boolean('is_blocked')
            ->allowEmpty('is_blocked');

        return $validator;
    }
792014
public function validationDefault(Validator $validator) : Validator
    {
        // configurable in config/csv_migrations.php
        if (! Configure::read('CsvMigrations.tableValidation')) {
            return $validator;
        }

        return $this->validationEnabled($validator);
    }
144152
public function validationDefault(Validator $validator)
    {
        $validator
            ->requirePresence('name')
            ->add('name', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a content type name.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', 'Name need to be at least 3 characters long.'),
                ],
            ])
            ->requirePresence('slug', 'create')
            ->notEmpty('slug', __d('content', 'Machine-name cannot be left empty.'), 'create')
            ->add('slug', 'checkSlug', [
                'rule' => function ($value, $context) {
                    return (preg_match('/^[a-z0-9\-]{3,}$/', $value) === 1);
                },
                'message' => __d('content', 'Invalid machine-name.'),
            ])
            ->requirePresence('title_label')
            ->add('title_label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('content', 'You need to provide a "Title Label".'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('content', '"Title Label" need to be at least 3 characters long.'),
                ],
            ]);

        return $validator;
    }
365749
protected function _setValidator($validator)
    {
        if (!is_null($validator) && !($validator instanceof ValidatorInterface)) {
            throw $this->_createInvalidArgumentException($this->__('Invalid validator'), null, null, $validator);
        }

        $this->validator = $validator;
    }
598383
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

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

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

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

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

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

        $validator
            ->uuid('created_by')
            ->notEmpty('created_by');

        $validator
            ->uuid('modified_by')
            ->notEmpty('modified_by');

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

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

        return $this;
    }
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;
    }
1249350
public function validationDefault(Validator $validator)
    {
        $validator
            ->allowEmpty('id', 'create')
            ->requirePresence('filepath', 'create')
            ->notEmpty('filepath')
            ->requirePresence('filename', 'create')
            ->notEmpty('filename')
            ->requirePresence('filetype', 'create')
            ->notEmpty('filetype')
            ->add('filesize', 'valid', ['rule' => 'numeric'])
            ->requirePresence('filesize', 'create')
            ->notEmpty('filesize')
            ->requirePresence('model', 'create')
            ->notEmpty('model')
            ->requirePresence('foreign_key', 'create')
            ->notEmpty('foreign_key');

        return $validator;
    }
1334453
public function validationDefault(Validator $validator)
    {
        return $validator
            ->requirePresence('enable_caching', true, __d('wasabi_core', 'Please select a cache status.'))
            ->add('enable_caching', 'inList', [
                'rule' => ['inList', ['0', '1']],
                'message' => __d('wasabi_core', 'Please select a valid cache status.')
            ])
            ->requirePresence('cache_duration', true, __d('wasabi_core', 'Please select a cache duration.'))
            ->add('cache_duration', 'custom', [
                'rule' => function ($value, $context) {
                    return in_array($value, $this->cacheDurations);
                },
                'message' => __d('wasabi_core', 'Please select a valid cache duration.')
            ]);
    }
564117
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name', 'update')
            ->allowEmpty('name', 'create');

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

        $validator
            ->requirePresence('content', 'create')
            ->notEmpty('content')
            ->isArray('content')
            ->add('content', 'validateSaved', [
                'rule' => function ($value, $context) {
                    return is_array($value) ? array_key_exists('saved', $value) : false;
                },
                'message' => 'Missing required key "saved"'
            ])
            ->add('content', 'validateLatest', [
                'rule' => function ($value, $context) {
                    return is_array($value) ? array_key_exists('latest', $value) : false;
                },
                'message' => 'Missing required key "latest"'
            ]);

        return $validator;
    }
667716
public function validate($validator)
    {
        if ($this->checkHostname($this->Value())) {
            return true;
        }

        $validator->validationError(
            $this->getName(),
            _t('DomainNameField.INVALID_DOMAIN', 'Invalid domain name'),
            'validation'
        );
        return false;
    }
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;
    }
1349258
public function validationStrictPassword(Validator $validator): Validator
    {
        $validator
            ->add('password', [
                'minLength' => [
                    'rule' => ['minLength', $this->getConfig('minPasswordLength')],
                    'last' => true,
                    'message' => __d('ck_tools', 'validation.user.password_min_length'),
                ],
            ])
            ->add('password', 'passwordFormat', [
                'rule' => function ($value, $context) {
                    return $this->validFormat($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_invalid_format'),
            ])
            ->add('password', 'passwordNoUserName', [
                'rule' => function ($value, $context) {
                    return $this->checkForUserName($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_user_name_not_allowed'),
            ])
            ->add('password', 'passwordUsedBefore', [
                'rule' => function ($value, $context) {
                    return $this->checkLastPasswords($value, $context);
                },
                'message' => __d('ck_tools', 'validation.user.password_used_before'),
            ]);

        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;
    }