addValidator

@param ValidatorInterface|callable $validator

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

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

        return $this;
    }
1128011
public function addValidator (FormValidator $validator, $unshift = false)
    {
        if ($unshift)
            array_unshift($this->validators, $validator);
        else
            $this->validators[] = $validator;
        return $this;
    }
342657
public function withValidator($validator): void
    {
        $credentials = $this->only('email', 'expiration', 'token');
        $passwordResetBroker = app('auth.password')->broker($this->route('passwordResetBroker'));

        $validator->after(function ($validator) use ($passwordResetBroker, $credentials) {
            if (! ($user = $passwordResetBroker->getUser($credentials))) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::INVALID_USER));
            }

            if ($user && ! $passwordResetBroker->validateToken($user, $credentials)) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::INVALID_TOKEN));
            }

            if (! $passwordResetBroker->validateTimestamp($credentials['expiration'])) {
                $validator->errors()->add('email', trans('cortex/auth::'.PasswordResetBrokerContract::EXPIRED_TOKEN));
            }
        });
    }
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;
    }
1196813
private static function checkClass($validator)
    {
        if (! class_exists($validator)) {
            throw new InvalidArgumentException(
                "Class {$validator} does not exists."
            );
        }

        if (! is_subclass_of($validator, ValidatorInterface::class)) {
            throw new Exception\UnknownValidatorClassException(
                "The validator '{$validator}' is not defined or does not " .
                "implements the Slick\\Validator\\ValidatorInterface interface"
            );
        }

        return $validator;
    }
39694
public function addValidator(ValidatorInterface $validator)
    {
        if ($validator instanceof tao_helpers_form_validators_NotEmpty) {
            $this->addAttribute('required', true);
        }
        $this->validators[] = $validator;
    }
56101
public function withValidator($validator)
    {
        if ($validator->passes()) {
            $validator->after(function ($validator) {

                try {
                    // get validated data
                    $data = $this->validated();

                    // Set temporary DB connection
                    config(['database.connections.mysql' => [
                        'driver' => 'mysql',
                        'host' =>  $data['DB_HOST'],
                        'database' => $data['DB_DATABASE'],
                        'prefix' => $data['DB_PREFIX'],
                        'username' => $data['DB_USERNAME'],
                        'password' => $data['DB_PASSWORD'],
                        'charset' => 'utf8',
                        'collation' => 'utf8_unicode_ci',
                        'strict' => true,
                        'engine' => 'InnoDB',
                    ]]);

                    // Check DB connection and exists table
                    \DB::purge('mysql');
                    \DB::reconnect('mysql');
                    \DB::setTablePrefix($data['DB_PREFIX']);
                    \DB::connection()->getPdo();
                    if (is_null(\DB::connection('mysql')->getDatabaseName())) {
                        throw new InstallerFailed(__('msg.not_dbconnect'));
                    }

                    // 3 Manipulation of the database
                    \DB::beginTransaction();

                    // Make migrate
                    $exitCode = \Artisan::call('migrate', ['--force' => true]);
                    $outputMigrate = \Artisan::output();
                    session()->flash('flash_output_migrate', $outputMigrate);

                    \DB::commit();
                } catch (\InstallerFailed $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } catch (\PDOException $e) {
                    $validator->errors()->add('database', $e->getMessage());
                } finally {
                    \DB::rollback();
                }

            });
        }

        return $validator;
    }
91035
public function validationDefault(Validator $validator): \Cake\Validation\Validator
    {
        $validator
            ->add('id', 'valid', ['rule' => 'uuid'])
            ->allowEmpty('id', 'create');

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

        return $validator;
    }
721552
public function validationEnabled(Validator $validator) : Validator
    {
        $className = App::shortName(get_class($this), 'Model/Table', 'Table');
        $config = (new ModuleConfig(ConfigType::MIGRATION(), $className))->parse();
        $config = json_encode($config);
        if (false === $config) {
            return $validator;
        }
        $config = json_decode($config, true);
        $factory = new FieldHandlerFactory();

        foreach ($config as $column) {
            $validator = $factory->setValidationRules($this, $column['name'], $validator);
        }

        return $validator;
    }
946607
public function addValidators(array $validators)
    {
        foreach ($validators as $validator) {
            if ($validator === null) {
                continue;
            }

            $this->addValidator($validator);
        }

        return $this;
    }
641350
public function extend($validator)
	{
		$validator = is_array($validator) ? $validator : [$validator];

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

		return $this;
	}
1347168
protected function useValidator(Validator $validator)
    {
        if (substr($this->account, 2, 2) == '99') {
            return $validator === $this->validators[2]
                || $validator === $this->validators[3];

        } else {
            return  $validator !== $this->validators[2];

        }
    }
1369061
public function prepareValidator(\Asgard\Validation\ValidatorInterface $validator) {
		if($this->get('required'))
			$validator->rule('required', true);
		if($this->get('length'))
			$validator->rule('maxlength', $this->get('length'));
		if($this->get('in'))
			$validator->rule('in', [array_keys($this->get('in'))]);

		if(method_exists($this, '_prepareValidator'))
			$this->_prepareValidator($validator);

		$rules = isset($this->params['validation']) ? $this->params['validation']:[];
		if(!is_array($rules))
			$rules = [$rules];
		$validator->rules($rules);
	}
1043625
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

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

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

        return $validator;
    }
818723
public static function createFromClosure(Validator $validator, callable $callback): self
    {
        $self = new static($validator);

        $self->setCallback(function (array $attributes, string $name, array $parameters) use ($callback) {
            return $callback($attributes, $name, $parameters);
        });

        return $self;
    }
1269298
public function validator($type, $validator)
    {
        $this->validators[$type] = $validator;

        $this->resolver($type, function ($data, $resourceId) use ($type) {
            /** @var \Drp\JsonApiParser\Contracts\ValidatorExecutor[] $validators */
            $validators = Arr::wrap($this->validators[$type]);

            foreach ($validators as $validator) {
                $data['id'] = $resourceId;
                $validator->with($data);

                $result = $validator->passes();

                if (!$result) {
                    $errors = $validator->errors();

                    $types = explode('.', $type);
                    $key = end($types);

                    if ($resourceId !== null) {
                        $key .= '_' . $resourceId;
                    }

                    $this->errors[$key] = array_merge(Arr::get($this->errors, $key, []), $errors);
                }
            }
        });

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

        return $this;
    }