Run the gathered validation rules on the arguments.

@return void
768022
protected function validateArgs(): void
    {
        if (! $this->rules) {
            return;
        }

        $validator = validator(
            $this->args,
            $this->rules,
            $this->messages,
            [
                'root' => $this->root,
                'context' => $this->context,
                // This makes it so that we get an instance of our own Validator class
                'resolveInfo' => $this->resolveInfo,
            ]
        );

        if ($validator->fails()) {
            foreach ($validator->errors()->getMessages() as $key => $errorMessages) {
                foreach ($errorMessages as $errorMessage) {
                    $this->validationErrorBuffer->push($errorMessage, $key);
                }
            }
        }

        $path = implode(
            '.',
            $this->resolveInfo()->path
        );
        $this->validationErrorBuffer->flush(
            "Validation failed for the field [$path]."
        );

        // reset rules and messages
        $this->rules = [];
        $this->messages = [];
    }
407755
public function execute()
    {
        $regexp = '/^[0-9\ ]+$/';
        $result = filter_var($this->value, FILTER_VALIDATE_REGEXP, [
            'options' => [
                'regexp' => $regexp
            ]
        ]);
        
        if (!$result) {
            $this->msg = 'validator.rule.number';
        }
    }
1165983
public function validate()
	{
		$varValue = $this->getPost($this->strName);

		if (!empty($varValue) && !$this->isValidOption($varValue))
		{
			$this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalid'], (is_array($varValue) ? implode(', ', $varValue) : $varValue)));
		}

		parent::validate();
	}
145907
public function setupRules()
    {
        $this->rules->addMany([
            'call' => new Rule(new RegexMatcher(
                '/(?>(?<![^\\\]\\\)(?<=\n|\(|\)|\||;|`|^|do|if|then|else|fi|esac|done\$\(|^\$\s)\s*\b(\w+))(?!\s*=)/i'
            ), ['priority' => 1, 'context' => ['*none', '*expression']]),

            'comment' => new Rule(new CommentMatcher(['#'])),
            'string' => CommonFeatures::strings(['single' => '\'', 'double' => '"']),

            'keyword' => new Rule(new WordMatcher([
                'if', 'then', 'else', 'elif', 'fi', 'case', 'esac', 'for', 'select', 'while', 'until', 'do', 'done',
                'in', 'function', 'time', 'coproc'
            ]), ['priority' => 3]),

            'variable'  => [
                'assign' => new Rule(new RegexMatcher('/(\w+)[+-]?=/')),
                new Rule(new RegexMatcher('/(\$\w+)/i'), ['context' => ['*none', '*string.double']]),
                'special'  => new Rule(new RegexMatcher('/(\$[#@_])/i'), ['context' => ['*none', '*string.double']]),
                'argument' => new Rule(new RegexMatcher('/(\$\d+)/i'), ['context' => ['*none', '*string.double']]),
                new Rule(new RegexMatcher('/\$\{(\w+)(.*?)\}/i', [ 1 => Token::NAME, 2 => 'string' ]), ['context' => ['*none', '*string.double']])
            ],

            'number'    => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')),
            'delimiter' => new Rule(new RegexMatcher('/^(\$)/m')),

            'symbol.parameter' => new Rule(new RegexMatcher('/[\s|](-{1,2}[\w-]+=?)\b/i'), [
                'priority' => 0,
                'context'  => ['!string', '!comment', '!call']
            ]),

            'expression' => [
                new Rule(new RegexMatcher('/(?=(\$\(((?>[^$()]+|(?1))+)\)))/x'), [
                    'context' => Validator::everywhere(),
                    'factory' => new TokenFactory(LanguageToken::class),
                    'inject'  => $this
                ]),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:x[0-9a-fA-F]{1,2}|u\{[0-9a-fA-F]{1,6}\}|[0-7]{1,3}|.))/i'), [
                'context' => ['*']
            ]),
        ]);
    }
797089
private function execute() {

		if(false === $this -> getExecuted()) {

			foreach($this -> rules as $rule) {

				$value = $this -> getValue($rule -> field, $rule -> prefix);

				//Execute custom extended validator
				if($rule -> closure) {

					if(false === call_user_func($rule -> closure, $rule -> field, $value)) {

						$this -> setPasses(false);

						$instance = $this -> getMessageInstance();
						$instance :: setFieldnames([$rule -> field]);
						$instance :: setError($rule -> prefix, $rule -> field, $rule -> message);
					}

					continue;
				}

				//Execute build in validator
				$class = $this -> getRuleClass($rule -> rule);
				$class = new $class();

				//Set rule data
				$class -> setField($rule -> field);
				$class -> setValue($value);
				$class -> setPrefix($rule -> prefix);
				$class -> setParameters($rule -> parameters);
				$class -> setValidateAsArray($this -> isValidateArray($rule -> field));

				if(true === is_callable([$class, 'requestParameters'])) {
					
					$params = call_user_func_array([$class, 'requestParameters'], []);

					foreach($params as $param) {
						
						$value = $this -> getValue($param, $rule -> prefix);
						$class -> setValues($param, $value);
					}
				}

				//Check if rule passes
				if(false === $this -> isRequired($rule -> field, $value) && false === $class -> isValid()) {

					$this -> setPasses(false);
					$this -> setErrorMessage($rule, $class);

					foreach($this -> combine as $combine) {
						
						if($combine -> getName() === $rule -> field) {

							foreach($combine -> getFieldnames() as $fieldname) {

								$rule -> field = $fieldname;
								$this -> setErrorMessage($rule, $class);
							}

							break;
						}
					}
				}
			}

			$this -> setExecuted(true);
		}
	}
55612
final protected function runOnScenario(): void
    {
        if (\is_null($method = $this->validationScenarios['on'])) {
            return;
        }

        $this->{$method}(...$this->validationScenarios['parameters']);
    }
920094
protected function prepareForValidation(): void
    {
        $data = $this->all();

        // Set abilities
        if (! empty($data['abilities'])) {
            if ($this->user($this->route('guard'))->can('grant', \Cortex\Auth\Models\Ability::class)) {
                $abilities = array_map('intval', $this->get('abilities', []));
                $data['abilities'] = $this->user($this->route('guard'))->isA('superadmin') ? $abilities
                    : $this->user($this->route('guard'))->getAbilities()->pluck('id')->intersect($abilities)->toArray();
            } else {
                unset($data['abilities']);
            }
        }

        $this->replace($data);
    }
231974
private function setUpValidations()
    {
        $this
            ->addValidation(array($this, 'amountNotNull'), 'HpsArgumentException', 'AddValue needs an amount')
            ->addValidation(array($this, 'currencyNotNull'), 'HpsArgumentException', 'AddValue needs an currency')
            ->addValidation(array($this, 'trackDataNotNull'), 'HpsArgumentException', 'AddValue needs an trackData')
            ->addValidation(array($this, 'pinBlockNotNull'), 'HpsArgumentException', 'AddValue needs an pinBlock');
    }
904609
public function execute()
    {
        $result = strtotime($this->value) === false ? false : true;
        
        if (!$result) {
            $this->msg = 'validator.rule.date';
        }
    }
1185372
protected function prepareForValidation(): void
    {
        $data = $this->all();
        $duration = explode(' - ', $data['duration']);

        $data['starts_at'] = (new Carbon($duration[0]))->toDateTimeString();
        $data['ends_at'] = (new Carbon($duration[1]))->toDateTimeString();

        $this->replace($data);
    }
214326
public function run()
    {
        if (!is_array($rules = $this->getRules())) {
            $rules = $this->convertToArray($rules);
        }

        if (!is_array($datas = $this->getDatas())) {
            $datas = $this->convertToArray($datas);
        }

        foreach ($rules as $key => $rule) {
            $parsedRules = explode("|", $rule);

            foreach ($parsedRules as $parsedRule) {
                $required = $this->handleRule($parsedRule, $key, $datas);

                if ($required !== null && $required === false) {
                    break;
                }
            }
        }
    }
478143
public function setupRules()
    {
        parent::setupRules();

        $this->rules->validator = new Validator(
            ['!format.block.code', '!format.monospace', '!operator.escape', '!operator', '!tag']
        );

        $this->rules->addMany([
            'format.header' => [
                new Rule(new RegexMatcher('/^\s{0,3}(#+.+?)\r?$/m')),
                new Rule(new RegexMatcher('/^([^\r\n]+?)^(?:-+|=+)\R?$/m'))
            ],
            'format.italics'   => new Rule(
                new RegexMatcher('/(?:^|[^*_])(?P<italics>(?P<i>[*_])(?>[^*_\r\n]|(?:(?P<b>[*_]{2})(?>[^*_\r\n]|(?&italics))*?\g{b}))+\g{i})/'), [
                    'italics' => Token::NAME
                ]
            ),
            'format.bold'  => new Rule(
                new RegexMatcher('/(?P<bold>(?P<b>\*\*|__)(?>[^*_\r\n]|(?:(?P<i>[*_]{2})(?>[^*_\r\n]|(?&bold))*?\g{i}))+\g{b})/', [
                    'bold' => Token::NAME
                ])
            ),
            'format.strike'    => new Rule(new RegexMatcher('/(~~.+?~~)/')),
            'format.monospace' => [
                new Rule(new RegexMatcher('/(?:[^`]|^)(`.*?`)/')),
                new Rule(new RegexMatcher('/(``.*?``)/')),
                new Rule(new RegexMatcher('/^((?:(?: {4,}|\t).*?(?>\R|$)+?)+)/m')),
            ],

            'operator.list.ordered'   => new Rule(new RegexMatcher('/^\s*(\d+[.)])/m')),
            'operator.list.unordered' => new Rule(new RegexMatcher('/^\s*([-+*])/m'), [
                'context' => ['none'],
                'priority' => 1
            ]),

            'string.quote'       => new Rule(new RegexMatcher('/((?:^>.*?\R)+)/m')),
            'format.block.code'  => [
                new Rule(
                    new DelegateRegexMatcher(
                        '/^```(.*?)\R(.*?)\R^```/ms',
                        function($match, TokenFactoryInterface $factory) {
                            $lang = KeyLighter::get()->getLanguage($match[1][0]);
                            yield $factory->create(Token::NAME, ['pos' => $match[0][1], 'length' => strlen($match[0][0])]);
                            yield $factory->create(
                                "language.{$lang->getIdentifier()}", [
                                    'pos'    => $match[2][1],
                                    'length' => strlen($match[2][0]),
                                    'inject' => $lang,
                                    'class'  => LanguageToken::class,
                                ]
                            );
                        }
                    ), [
                        'context'     => Validator::everywhere(),
                        'postProcess' => true,
                        'priority'    => 1000
                    ]
                ),
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/')),

            'operator.horizontal' => new Rule(new RegexMatcher('/^\s{,3}(([-*_])( ?\2)+)\R/m'), [
                'priority' => 2
            ]),

            'symbol.link'  => new Rule(new RegexMatcher('/[^!](\[(?:[^\[\]]|!\[.*?\]\(.*?\))*\])/i')),
            'symbol.url'   => new Rule(new RegexMatcher('#(<(https?://|[^/])[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|]>|https?://[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|])#i'), [
                'priority' => 0,
            ]),
            'symbol.image' => new Rule(new RegexMatcher('/(!)(\[.*?\])\(.*?\)/i', [
                1 => 'operator.image',
                2 => '$.title',
            ])),
        ]);
    }
1357124
protected static function run_validation()
	{
		// storage for collected errors
		$errors = array();

		// validate the auth configuration file
		if ( ! is_file($file = APPPATH.'config'.DS.'auth.php'))
		{
			$errors[] = \Fuel::clean_path($file).' does not exist.';
		}
		else
		{
			\Config::load('auth', true);
			if ( ! $driver = \Config::get('auth.driver', false))
			{
				$errors[] = \Fuel::clean_path($file).' does not define an auth driver.';
			}
			elseif ($driver != 'Ormauth')
			{
				$errors[] = \Fuel::clean_path($file).' is not configured to use the Ormauth driver.';
			}
		}

		// validate the simpleauth configuration file
		if ( ! is_file($file = APPPATH.'config'.DS.'simpleauth.php'))
		{
			$errors[] = \Fuel::clean_path($file).' does not exist.';
		}
		else
		{
			\Config::load('simpleauth', true);
			if ( ! $table = \Config::get('simpleauth.table_name', false))
			{
				$errors[] = \Fuel::clean_path($file).' does not define a user table.';
			}
			elseif ( ! \DBUtil::table_exists($table))
			{
				$errors[] = \Fuel::clean_path($file).' defines a table that does not exist.';
			}
			else
			{
				// store the table name for future use
				static::$data['simpleauth_table'] = $table;
			}
		}

		// validate the ormauth configuration file
		if ( ! is_file($file = APPPATH.'config'.DS.'ormauth.php'))
		{
			$errors[] = \Fuel::clean_path($file).' does not exist.';
		}
		else
		{
			$config = \Config::load('ormauth', true);
			if ( ! $table = \Config::get('ormauth.table_name', false))
			{
				$errors[] = \Fuel::clean_path($file).' does not define a user table.';
			}
			elseif ( ! \DBUtil::table_exists($table))
			{
				$errors[] = \Fuel::clean_path($file).' defines a table that does not exist.';
			}
			else
			{
				// store the table name for future use
				static::$data['ormauth_table'] = $table;
			}

			if ( ! $cache_prefix = \Config::get('ormauth.cache_prefix', false) or empty($cache_prefix))
			{
				$errors[] = \Fuel::clean_path($file).' does not define a cache_prefix.';
			}
			else
			{
				// store the cache prefix for future use
				static::$data['cache_prefix'] = $cache_prefix;
			}
		}

		// check if all migrations have run, and the migration system is consistent
		$migrations = \Config::load('migrations', true);
		if ( ! isset($migrations['version']['package']['auth'][6]))
		{
			$errors[] = 'Auth database migrations haven\'t run (succesfully).';
		}
		else
		{
			$result = \DB::select('*')->from($migrations['table'])->where('type', '=', 'package')->where('name', '=', 'auth')->execute();
			if (count($result) < 7)
			{
				$errors[] = 'Auth database migrations haven\'t run (succesfully).';
				$errors[] = 'There is a discrepancy between your migration configuration file and the migration table.';
			}
		}

		// check the fields of the users table
		$usertable = array(
			'id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true),
			'username' => array('type' => 'varchar', 'constraint' => 50, 'after' => 'id'),
			'password' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'username'),
			'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password'),
			'email' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'group_id'),
			'last_login' => array('type' => 'varchar', 'constraint' => 25, 'after' => 'email'),
			'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login'),
			'login_hash' => array('type' => 'varchar', 'constraint' => 255, 'after' => 'previous_login'),
			'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash'),
			'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id'),
			'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at'),
			);

		foreach ($usertable as $field => $value)
		{
			if (\DBUtil::field_exists(static::$data['ormauth_table'], $field))
			{
				unset($usertable[$field]);
			}
		}
		if ( ! empty($usertable))
		{
			$errors[] = 'User table "'.static::$data['ormauth_table'].'" is missing the field(s): '.implode(', ', array_keys($usertable));
		}

		// process the results of the validation
		if ($errors)
		{
			// display all errors
			\Cli::write('You environment did not validate:', 'light_red');

			foreach ($errors as $error)
			{
				\Cli::write('* '.$error);
			}

			return false;
		}

		// inform the user we're good to go
		\Cli::write('Environment validated', 'light_green');
		return true;
	}
904272
public function validate(): void
    {
        $paths = $this->getConfigPaths();

        foreach ($paths as $path) {
            WP_CLI::line(
                WP_CLI::colorize("%B====> Validating $path%n")
            );

            try {
                Toml::parseFile($path);
                WP_CLI::success("File '$path' is valid.");
            } catch (ParseException $parseException) {
                WP_CLI::error_multi_line([
                    $parseException->getMessage(),
                ]);

                WP_CLI::warning("File '$path' will be ignored.");
            }

            // Print a empty line for better UX.
            WP_CLI::line('');
        }
    }
110634
protected function _validate($args = null)
    {
        $this->_runtime = ($args === null) ? $this->params : $args;

        $errors = [];

        if (!isset($this->_runtime['type'])) {
            $this->_runtime['type'] = 'regular';
        }

        if (!isset($this->_runtime['debug'])) {
            $this->_runtime['debug'] = false;
        }

        // Validate Log path
        $this->_runtime['log'] = isset($this->_runtime['log'])
            ? $this->_runtime['log']
            : (Configure::read('CakeResque.Scheduler.log') && $this->_runtime['type'] === 'scheduler'
                ? Configure::read('CakeResque.Scheduler.log')
                : Configure::read('CakeResque.Worker.log')
            );
        if (substr($this->_runtime['log'], 0, 2) == './') {
            $this->_runtime['log'] = LOGS . substr($this->_runtime['log'], 2);
        } elseif (substr($this->_runtime['log'], 0, 1) != '/') {
            $this->_runtime['log'] = LOGS . $this->_runtime['log'];
        }

        // Validate Interval
        $this->_runtime['interval'] = isset($this->_runtime['interval'])
            ? $this->_runtime['interval']
            : (Configure::read('CakeResque.Scheduler.Worker.interval') && $this->_runtime['type'] === 'scheduler'
                ? Configure::read('CakeResque.Scheduler.Worker.interval')
                : Configure::read('CakeResque.Worker.interval')
            );
        if (!is_numeric($this->_runtime['interval'])) {
            $errors[] = __d('cake_resque', 'Interval time [{0}] is not valid. Please enter a valid number', $this->_runtime['interval']);
        } else {
            $this->_runtime['interval'] = (int)$this->_runtime['interval'];
        }

        // Validate workers number
        $this->_runtime['workers'] = isset($this->_runtime['workers']) ? $this->_runtime['workers'] : Configure::read('CakeResque.Worker.workers');
        if (!is_numeric($this->_runtime['workers'])) {
            $errors[] = __d('cake_resque', 'Workers number [{0}] is not valid. Please enter a valid number', $this->_runtime['workers']);
        } else {
            $this->_runtime['workers'] = (int)$this->_runtime['workers'];
        }

        $this->_runtime['queue'] = isset($this->_runtime['queue']) ? $this->_runtime['queue'] : Configure::read('CakeResque.Worker.queue');

        // Validate user
        if (isset($this->_runtime['user'])) {
            $this->_runtime['user'] = $this->_runtime['user'];
        } elseif (Configure::read('CakeResque.Worker.user')) {
            $this->_runtime['user'] = Configure::read('CakeResque.Worker.user');
        } else {
            $user = $this->__getProcessOwner();
            $this->_runtime['user'] = empty($user) ? get_current_user() : $user;
        }

        $this->_runtime['verbose'] = isset($this->params['verbose']) ? $this->params['verbose'] : Configure::read('CakeResque.Worker.verbose');

        $output = [];
        exec('id ' . $this->_runtime['user'] . ' 2>&1', $output, $status);
        if ($status != 0) {
            $errors[] = __d('cake_resque', 'User [{0}] does not exists. Please enter a valid system user', $this->_runtime['user']);
        }

        $this->_runtime['Log']['handler'] = isset($this->_runtime['log-handler'])
            ? $this->_runtime['log-handler']
            : (Configure::read('CakeResque.Scheduler.Log.handler') && $this->_runtime['type'] === 'scheduler'
                ? Configure::read('CakeResque.Scheduler.Log.handler')
                : Configure::read('CakeResque.Log.handler')
            );

        $this->_runtime['Log']['target'] = isset($this->_runtime['log-handler-target'])
            ? $this->_runtime['log-handler-target']
            : (Configure::read('CakeResque.Scheduler.Log.target') && $this->_runtime['type'] === 'scheduler'
                ? Configure::read('CakeResque.Scheduler.Log.target')
                : Configure::read('CakeResque.Log.target')
            );
        if (substr($this->_runtime['Log']['target'], 0, 2) == './') {
            $this->_runtime['Log']['target'] = TMP . 'logs' . DS . substr($this->_runtime['Log']['target'], 2);
        }

        if (!empty($errors)) {
            foreach ($errors as $error) {
                $this->err('<error>' . __d('cake_resque', 'Error') . ':</error> ' . $error);
            }
            $this->out();
        }

        return empty($errors);
    }
435419
public function validate(): void
    {
        $required = [
            'app_root',
            'app_name',
            'default_filesystem',
            'environment',
            'default_branch',
            'default_database_adapter',
            'default_database_importexport_adapter',
            'default_dir_mode',
            'default_file_mode',
            'platform',
            'relative_document_root',
            'repo_url',
        ];
        $missingRequired = [];
        foreach ($required as $name) {
            if (empty($this->config[$name])) {
                $missingRequired[] = $name;
            }
        }
        if ($missingRequired) {
            throw new Exception\RuntimeException(
                'Missing required values for top level configuration key(s): "' . implode('", "', $missingRequired)
                . '"'
            );
        }

        if (!in_array(
            $this->config['file_layout'],
            [
                FileLayoutInterface::STRATEGY_BLUE_GREEN,
                FileLayoutInterface::STRATEGY_DEFAULT
            ]
        )) {
            throw new Exception\DomainException("Invalid file layout \"{$this->config['file_layout']}\".");
        }

        $this->buildConfig->validate();
        $this->deployConfig->validate();
        $this->snapshotConfig->validate();
        $this->skeletonConfig->validate();
    }
915663
protected function validate()
    {
        if (!empty($this->errors)) {
            // already validated
            return;
        }

        $this->errors = [];

        foreach ($this->rules as $field => $rules) {

            $value = $this->getValue($field);

            foreach ($this->provider->getRules($rules) as $rule) {
                if ($rule->ignoreEmpty($value) && empty($rule->hasConditions())) {
                    continue;
                }

                foreach ($rule->getConditions() as $condition) {
                    if (!$condition->isMet($this, $field, $value)) {
                        // condition is not met, skipping validation
                        continue 2;
                    }
                }

                if (!$rule->validate($this, $field, $value)) {
                    // got error, jump to next field
                    $this->errors[$field] = $rule->getMessage($field, $value);
                    break;
                }
            }
        }
    }