Validate defined rules in app
@return bool
@throws SyntaxException
335134
final public function validate(): bool
    {
        // validate csrf token if required
        if ($this->_tokenRequired && !$this->_tokenOk) {
            App::$Session->getFlashBag()->add('warning', __('Hack attention: security token is wrong!'));
            return false;
        }
        // get all rules as array from method rules()
        $rules = $this->rules();
        // get default values of attributes
        $defaultAttr = $this->getAllProperties();

        // start validation: on this step class attribute values will be changed to input data if it valid
        $success = $this->runValidate($rules);

        // get not-passed validation fields as array
        $badAttributes = $this->getBadAttributes();
        // prevent warnings
        if (Any::isArray($badAttributes) && count($badAttributes) > 0) {
            foreach ($badAttributes as $attr) {
                if (Str::contains('.', $attr)) { // sounds like dot-separated array attr
                    $attrName = strstr($attr, '.', true); // get attr name
                    $attrArray = trim(strstr($attr, '.'), '.'); // get dot-based array path

                    $defaultValue = new DotData($defaultAttr); // load default attr

                    $dotData = new DotData($this->{$attrName}); // load local attr variable
                    $dotData->set($attrArray, $defaultValue->get($attr)); // set to local prop. variable default value

                    $this->{$attrName} = $dotData->export(); // export to model
                } else {
                    $this->{$attr} = $defaultAttr[$attr]; // just set ;)
                }
                // add message about wrong attribute to session holder, later display it
                $attrLabel = $attr;
                if ($this->getLabel($attr) !== null) {
                    $attrLabel = $this->getLabel($attr);
                }

                App::$Session->getFlashBag()->add('warning', __('Field "%field%" is incorrect', ['field' => $attrLabel]));
            }
        }

        return $success;
    }
40229
protected function areCodeValid(): bool
    {
        return
            Dispatcher::NOT_FOUND === DispatcherInterface::ROUTE_NOT_FOUND &&
            Dispatcher::FOUND === DispatcherInterface::ROUTE_FOUND &&
            Dispatcher::METHOD_NOT_ALLOWED === DispatcherInterface::ROUTE_METHOD_NOT_ALLOWED;
    }
785084
public function validationApplies()
    {
        $return = true;

        if ($criteria = $this->owner->validationLogicCriteria) {
            $fields = $this->owner->rootFieldList();
            if (eval($criteria->phpEvalString()) === false) {
                throw new Exception("There is a syntax error in the constaint logic phpEvalString \"{$criteria->phpEvalString()}\"");
            }
            $return = eval('return ' . $criteria->phpEvalString());
        }

        return $return;
    }
1090901
public function isValid()
    {
        $this->errors = array();

        foreach ($this->rules() as $rule) {
            $fields = array_map('trim', explode(',', $rule[0]));
            $ruleName = $rule[1];
            $params = array_slice($rule, 2);

            // check scenario
            if (!empty($rule['on'])) {
                $onScenarios = explode(',', $rule['on']);
                if (!in_array($this->getScenario(), $onScenarios)) {
                    continue;
                }
            }

            if (!empty($rule['except'])) {
                $exceptScenarios = explode(',', $rule['except']);
                if (in_array($this->getScenario(), $exceptScenarios)) {
                    continue;
                }
            }

            if (method_exists($this, $ruleName)) {
                // method
                foreach ($fields as $field) {
                    $this->{$ruleName}($field, $params);
                }
            } else {
                // validator class
                $validatorClassName = $this->getValidatorClassNameByRuleName($ruleName);

                /* @var $validator \Sokil\Mongo\Validator */
                $validator = new $validatorClassName;
                if (!$validator instanceof Validator) {
                    throw new Exception('Validator class must implement \Sokil\Mongo\Validator class');
                }

                $validator->validate($this, $fields, $params);
            }
        }

        return !$this->hasErrors();
    }
413191
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return true;
        }
        
        if(!\is_callable($value)) {
            return 'formvalidator_make_callable';
        }
        
        if(empty($options)) {
            throw new \LogicException('Invalid options value given for callback rule');
        }
        
        /** @var \ReflectionMethod|\ReflectionFunction  $prototype */
        
        if(\is_array($value)) {
            $prototype = new \ReflectionMethod($value[0], $value[1]);
        } else {
            $prototype = new \ReflectionFunction($value);
        }
        
        $options = \explode('=', $options, 2);
        
        if(!empty($options[0])) {
            $params = \explode(',', $options[0]);
            
            /** @var \ReflectionParameter  $param */
            foreach($prototype->getParameters() as $pos => $param) {
                $type = $param->getType();
                
                if(!isset($params[$pos])) {
                    return array('formvalidator_make_callback_param_superfluos', array('{0}' => $pos));
                } elseif($params[$pos] === '') {
                    continue; // "mixed" type - wildcard
                } elseif(($type === null && $params[$pos] !== '') || \trim($params[$pos], '?') !== $type->getName()) {
                    return array('formvalidator_make_callback_param', array('{0}' => $pos, '{1}' => \trim($params[$pos], '?')));
                } elseif($params[$pos][0] === '?' && !$type->allowsNull()) {
                    return array('formvalidator_make_callback_param_nullable', array('{0}' => $pos));
                } elseif(\substr($params[$pos], -1) === '?' && !$param->isOptional()) {
                    return array('formvalidator_make_callback_param_optional', array('{0}' => $pos));
                }
            }
        }
        
        if(!empty($options[1])) {
            $return = $prototype->getReturnType();
            
            if($return === null) {
                return array('formvalidator_make_callback_return', array('{0}' => $options[1]));
            } elseif(($return->allowsNull() ? '?' : '').$return->getName() !== $options[1]) {
                return array('formvalidator_make_callback_return_type', array('{0}' => $options[1], '{1}' => $return->getName()));
            }
        }
        
        return true;
    }
954637
public function validate($rules = [], $errors = [])
    {
        foreach ($rules as $param => $subRules) {
            $paramValue = $this->getParam($param);
            foreach ($subRules as $key => $rule) {
                $isError = false;
                if (!is_array($rule)) {
                    switch ($rule) {
                        case self::VALIDATE_REQUIRED:
                            if (is_null($paramValue)) {
                                $isError = true;
                            }
                            break;
                        case self::VALIDATE_MOBILE:
                            if (!ValidationHelper::isMobile($paramValue)) {
                                $isError = true;
                            }
                            break;
                    }
                } else {
                    switch ($key) {
                    case self::VALIDATE_ENUM:
                        if (!in_array($paramValue, $rule)) {
                            $isError = true;
                        }
                        break;
                    }
                }
                if ($isError) {
                    $errCode = self::ERROR_INVALID_PARAM;
                    $errMsg = self::errorMsg[self::ERROR_INVALID_PARAM];
                    if (is_array($rule)) {
                        $rule = $key;
                    }
                    if (isset($errors[$param][$rule]['code'])) {
                        $errCode = $errors[$param][$rule]['code'];
                    }
                    if (isset($errors[$param][$rule]['msg'])) {
                        $errMsg = str_replace('{param}', $param, $errors[$param][$rule]['msg']);
                    }
                    throw new ParamException($errMsg, $errCode);
                }
            }
        }
    }
943881
protected function validateEditor()
    {
        $this->setSubmitted('editor', null, false);

        $this->setSubmitted('user_id', $this->uid);
        $this->setSubmitted('path', $this->data_file);
        $this->setSubmitted('module', $this->data_module);

        $this->validateSyntaxEditor();

        return !$this->hasErrors();
    }
821018
public function validate()
	{
		$this->errors->set();

		foreach ($this->rules as $key => $rule) {
			list ($fields, $type, $options) = $this->parseRule($rule);

			if (!$validator = $this->validators->$type) {
				$validator = $this->create($type);
				$this->validators->$type = $validator;
			}

			foreach ($fields as $key => $field) {
				$value = $this->dataSet->$field;

				if (!$validator->validate($value, $options)) {
					$this->addErrors($field, $validator->getErrors());
				}
			}
		}

		return !$this->hasErrors();
	}
111984
protected function validateLimitSettings()
    {
        $field = 'limit';
        $limit = $this->getSubmitted($field);

        if (!ctype_digit($limit) || strlen($limit) > 3) {
            $this->setErrorInteger($field, $this->translation->text('Limit'));
            return false;
        }

        return true;
    }
740993
protected function validateEditInstall()
    {
        $this->setSubmitted('settings');
        $this->setSubmitted('store.host', $this->server->httpHost());
        $this->setSubmitted('store.language', $this->install_language);
        $this->setSubmitted('store.basepath', trim($this->request->base(true), '/'));

        $this->validateComponent('install');

        return !$this->hasErrors(false);
    }
111065
protected function validate()
    {
        if (!CommonUtils::isRegexExpr($this->pattern)) {
            return false;
        }

        return (bool) preg_match(
            $this->pattern,
            $this->getRequestValue()
        );
    }
1335403
protected function validateExtensionSettings()
    {
        $field = 'extension_limit';
        $rules = $this->getSubmitted($field);

        $errors = $converted = array();
        foreach (gplcart_string_explode_multiline($rules) as $line => $rule) {

            $line++;

            $parts = gplcart_string_explode_whitespace($rule, 2);

            if (count($parts) != 2) {
                $errors[] = $line;
                continue;
            }

            list($role_id, $extensions) = $parts;

            if (!$this->isValidRoleSettings($role_id)) {
                $errors[] = $line;
                continue;
            }

            $filtered_extensions = array_filter(array_map('trim', explode(',', $extensions)));

            foreach ($filtered_extensions as $extension) {
                if (!ctype_alnum($extension) || strlen($extension) > 250) {
                    $errors[] = $line;
                    break;
                }
            }

            $converted[$role_id] = $filtered_extensions;
        }

        if (!empty($errors)) {
            $error = $this->translation->text('Error on line @num', array('@num' => implode(',', $errors)));
            $this->setError($field, $error);
            return false;
        }

        $this->setSubmitted($field, $converted);
        return true;
    }
1189220
public function passes()
    {
        foreach ($this->userRules as $inputName => $userRule) {
            $rules = $this->parser->setCommand($userRule)->parse();
            $this->validateInput($inputName, $rules);
        }

        return $this->isValid;
    }
656364
public function validate() {

		$result = parent::validate();

		// Confirm that the current search suggestion matches the minimum autocomplete length and doesn't already exist.

		if($result->isValid() && (strlen($this->Term) < 3)) {
			$result->addError('Minimum autocomplete length required!');
		}
		else if($result->isValid() && ExtensibleSearchSuggestion::get_one(ExtensibleSearchSuggestion::class, array(
			'ID != ?' => (int)$this->ID,
			'Term = ?' => $this->Term,
			'ExtensibleSearchPageID = ?' => $this->ExtensibleSearchPageID
		))) {
			$result->addError('Suggestion already exists!');
		}

		// Allow extension customisation.

		$this->extend('validateExtensibleSearchSuggestion', $result);
		return $result;
	}
916919
private function syntaxError(): void
    {
        throw new SyntaxErrorException(
            $this->lexer->getInputUntilPosition(PHP_INT_MAX),
            $this->lexer->lookahead['value'] ?: 'end of string',
            (int) $this->lexer->lookahead['position']
        );
    }
1259244
public function validate()
	{
		$errors = array();
		foreach ($this->config->getAllTypeMaps() as $typeMap) {
			try {
				$typeMap->validate();
			} catch (\Exception $e) {
				$errors[] = $e->getMessage();
			}
		}

		if (!empty($errors)) {
			throw new ValidationException(implode("\n\n", $errors));
		}
	}
792401
public function validate()
    {
        $valid = true;
        foreach ($this->object->validationRules() as $rule) {
            if (isset($rule[0], $rule[1])) {
                $properties = $rule[0];
                $validator = 'validate' . $rule[1];
                if (!method_exists($this, $validator)) {
                    throw new NostoException(sprintf(
                        'Nosto validator "%s" does not exist.',
                        $validator
                    ));
                }
                $params = array_merge(array($properties), array_slice($rule, 2));
                $isValid = call_user_func_array(array($this, $validator), $params);
                if (!$isValid) {
                    $valid = false;
                }
            }
        }

        return $valid;
    }