Default validation rules.

@param Validator $validator The validator to customize.
@return Validator
508574
public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty(
                'instance_name',
                __d('wasabi_core', 'Please enter a name for your app.')
            )
            ->notEmpty(
                'instance_short_name',
                __d('wasabi_core', 'Please enter a short name for your app.')
            )
            ->notEmpty(
                'Email__email_sender',
                __d('wasabi_core', 'Please enter an email address.')
            )
            ->notEmpty(
                'Email__email_sender_name',
                __d('wasabi_core', 'Please enter a name for the email sender.')
            )
            ->add('Email__email_sender', 'validEmail', [
                'rule' => 'email',
                'message' => __d('wasabi_core', 'Please enter a valid email address.')
            ])
            ->notEmpty(
                'Login__HeartBeat__max_login_time',
                __d('wasabi_core', 'Please choose a maximum login time.')
            )
            ->add('Login__HeartBeat__max_login_time', 'valid', [
                'rule' => function ($value, $context) {
                    return in_array((int)$value, [900000, 1800000, 2700000, 3600000, 6400000]);
                },
                'message' => __d('wasabi_core', 'Please choose a valid maximum login time.')
            ])
            ->numeric(
                'Auth__max_login_attempts',
                __d('wasabi_core', 'Please enter a number above 0.')
            )
            ->greaterThan(
                'Auth__max_login_attempts',
                0,
                __d('wasabi_core', 'Please enter a number above 0.')
            )
            ->notEmpty(
                'User__has_username',
                __d('wasabi_core', 'Please choose if users have a username.')
            )
            ->notEmpty(
                'User__has_firstname_lastname',
                __d('wasabi_core', 'Please choose if users have a firstname and lastname.')
            )
            ->notEmpty(
                'User__allow_timezone_change',
                __d('wasabi_core', 'Please choose if users may change his timezone.')
            )
            ->notEmpty(
                'User__belongs_to_many_groups',
                __d('wasabi_core', 'Please choose if users may belong to multiple groups.')
            );
    }
13736
protected function _buildValidator(Validator $validator)
    {
        $validator = new AppValidator;

        //Filename
        $validator->add('filename', 'extension', [
            'message' => __d('me_cms', 'Valid extensions: {0}', 'sql, sql.gz, sql.bz2'),
            'rule' => function ($value) {
                return (bool)preg_match('/[^\.]\.sql(\.(bz2|gz))?$/', $value);
            },
        ])->requirePresence('filename');

        return $validator;
    }
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;
    }
160413
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.
        $implicit = $this->implicitExtensions;

        $validator->addImplicitExtensions($implicit);

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

        $validator->setFallbackMessages($this->fallbackMessages);
    }
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;
    }
221024
public function setValidator($validator)
    {
        $this->callBeforeListeners('setValidator', [$validator]);
        $this->validator = $validator;
        $this->callAfterListeners('setValidator', [$validator]);
    }
366716
public static function isValid($validator, $value)
    {
        /** @var ValidatorInterface $validator */
        $validator = static::create($validator);
        $result = $validator->isValid($value);
        static::$_messages = $validator->getMessages();
        return $result;
    }
634905
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('source');

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

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

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

        $validator
            ->scalar('response_status')
            ->maxLength('response_status', 255)
            ->allowEmpty('response_status');

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

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

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

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

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

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

        return $validator;
    }
704390
public function addValidation(Validator $validator) {
		$validator->requirePresence('captcha_result');
		$validator->add('captcha_result', [
			'required' => [
				'rule' => 'notBlank',
				'last' => true
			],
		]);

		/** @deprecated Use PassiveCaptcha Behavior */
		if ($this->getConfig('dummyField')) {
			$validator->requirePresence($this->getConfig('dummyField'));
			$validator->allowEmpty($this->getConfig('dummyField'));
			$validator->add($this->getConfig('dummyField'), [
				'dummyField' => [
					'rule' => function ($value, $context) {
						return $value === '';
					},
					'last' => true
				],
			]);
		}

		$this->_engine->buildValidator($validator);
		if ($this->getConfig('minTime')) {
			$validator->add('captcha_result', [
				'minTime' => [
					'rule' => 'validateCaptchaMinTime',
					'provider' => 'table',
					'message' => __('You were too fast'),
					'last' => true
				],
			]);
		}
		if ($this->getConfig('maxTime')) {
			$validator->add('captcha_result', [
				'maxTime' => [
					'rule' => 'validateCaptchaMaxTime',
					'provider' => 'table',
					'message' => __('You were too slow'),
					'last' => true
				],
			]);
		}
	}
641350
public function extend($validator)
	{
		$validator = is_array($validator) ? $validator : [$validator];

		$this->validators = array_merge($this->validators, $validator);

		return $this;
	}
774295
public function validationDefault(Validator $validator)
    {
        $validator
            ->allowEmpty('url')
            ->add('url', 'checkUrl', [
                'rule' => function ($url, $context) {
                    $plainString = (
                        strpos($url, 'javascript:') === 0 ||
                        strpos($url, 'mailto:') === 0 ||
                        strpos($url, 'tel:') === 0 ||
                        strpos($url, 'sms:') === 0 ||
                        strpos($url, '#') === 0 ||
                        strpos($url, '?') === 0 ||
                        strpos($url, '//') === 0 ||
                        strpos($url, '://') !== false
                    );

                    if ($plainString) {
                        return true;
                    } else {
                        $full = Validation::url($url);
                        $internal = str_starts_with($url, '/');

                        return $full || $internal;
                    }
                },
                'message' => __d('menu', 'Invalid URL. Internal links must start with "/", e.g. "/article-my-first-article{0}"', CONTENT_EXTENSION),
                'provider' => 'table',
            ])
            ->requirePresence('title')
            ->add('title', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('menu', 'You need to provide a title.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('menu', 'Title need to be at least 3 characters long.'),
                ],
            ])
            ->add('activation', 'validActivation', [
                'rule' => function ($value, $context) {
                    return in_array($value, ['auto', 'any', 'none', 'php']);
                },
                'message' => __d('menu', 'Please select an activation method.'),
                'provider' => 'table',
            ])
            ->allowEmpty('active')
            ->add('active', 'validPHP', [
                'rule' => function ($value, $context) {
                    if (!empty($context['data']['activation']) && $context['data']['activation'] === 'php') {
                        return strpos($value, '<?php') !== false && strpos($value, '?>') !== false;
                    }

                    return true;
                },
                'message' => __d('menu', 'Invalid PHP code, make sure that tags "&lt;?php" & "?&gt;" are present.')
            ]);

        return $validator;
    }
693987
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

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

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

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

        $validator
            ->allowEmpty('subfolder');

        $validator
            ->allowEmpty('mimetype');

        $validator
            ->add('size', 'valid', ['rule' => 'numeric'])
            ->requirePresence('size', 'create')
            ->notEmpty('size');

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

        $validator
            ->add('upload_complete', 'valid', ['rule' => 'boolean'])
            ->requirePresence('upload_complete', 'create')
            ->notEmpty('upload_complete');

        $validator
            ->allowEmpty('label');

        $validator
            ->add('created_by', 'valid', ['rule' => 'numeric'])
            ->requirePresence('created_by', 'create')
            ->notEmpty('created_by');

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

        return $validator;
    }
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;
    }
878452
public function setValidators($validators = [])
    {
        if (is_array($validators)) {
            $this->validators = $validators;
        } else {
            $this->validators = func_get_args();
            if (count($this->validators) == 1 && is_string($this->validators[0])) {
                $this->validators = explode(',', $this->validators[0]);
            }
        }

        if (in_array('required', $this->validators)) {
            $this->setRequired();
            unset($this->validators[array_search('required', $this->validators)]);
        }


        return $this;

    }
236753
public function validationChangePassword($validator) {
		$validator->setProvider('userBehavior', $this);

		$validator = $this->validationPassword($validator);
		$validator = $this->validationConfirmPassword($validator);
		$validator = $this->validationOldPassword($validator);

		return $validator;
	}