Adds all the custom rules

@throws ValidateException
767329
protected function loadRules()
    {
        $old_cwd = getcwd();
        chdir(__DIR__);
        $path = 'Validate' . DIRECTORY_SEPARATOR . 'Rules';
        if (! is_dir($path)) {
            throw new ValidateException("Rules Directory " . $path . " isn't a directory...");
        }
        
        $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::LEAVES_ONLY);
        
        foreach ($files as $file) {
            if (! $file->isDir()) {
                $name = '\\JaegerApp\\' . str_replace('/', '\\', str_replace('.php', '', $file->getPathname()));
                $class = $name;
                if (class_exists($class)) {
                    $rule = new $class();
                    if ($rule instanceof Validate\RuleInterface) {
                        self::addRule($rule->getName(), array(
                            $rule,
                            'validate'
                        ), $rule->getErrorMessage());
                    }
                }
            }
        }
        
        chdir($old_cwd);
    }
532175
public function setupRules()
    {
        $standard = new Validator(['!string', '!comment']);

        $this->rules->addMany([
            'keyword' => new Rule(new WordMatcher([
                'and', 'del', 'from', 'not', 'while', 'as', 'elif', 'global', 'or', 'with', 'assert', 'else', 'if',
                'pass', 'yield', 'break', 'except', 'import', 'print', 'class', 'exec', 'in', 'raise', 'continue',
                'finally', 'is', 'return', 'def', 'for', 'lambda', 'try',
            ])),

            'operator' => new Rule(
                new RegexMatcher('/([-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~])|\b(or|and|not)\b/'), [
                    'priority' => -1
                ]
            ),

            'expression' => new Rule(new RegexMatcher('/\{(\S+)\}/'), [
                'context' => ['string']
            ]),

            'variable' => [
                new Rule(new RegexMatcher('/[^\w.]([a-z_]\w*)\.\w/i')),
                'property' => new Rule(new RegexMatcher('/(?=(?:\w|\)|\])\s*\.([a-z_]\w*))/i'), [
                    'priority' => -2,
                    'context' => ['*none', '*expression']
                ]),
            ],

            'symbol' => [
                new Rule(new RegexMatcher('/import\s+([a-z_][\w.]*)(?:\s*,\s*([a-z_][\w.]*))*/i', [
                    1 => Token::NAME,
                    2 => Token::NAME,
                ])),
                'library' => new Rule(new RegexMatcher('/from\s+([a-z_][\w.]*)\s+import/i', [
                    1 => Token::NAME,
                ]))
            ],

            'operator.escape' => new Rule(new RegexMatcher('/(\\\(?:\R|.|[0-7]{3}|x\x{2}))/s'), [
                'context' => Validator::everywhere()
            ]),

            'comment' => new Rule(new CommentMatcher(['#'])),
            'constant.special' => [
                new Rule(new WordMatcher(['True', 'False', 'NotImplemented', 'Ellipsis'], [
                    'case-sensitivity' => true
                ])),
                new Rule(new RegexMatcher('/\b(__\w+__)\b/'))
            ],
            'call' => new Rule(new RegexMatcher('/([a-z_]\w*)\s*\(/i'), ['priority' => 2]),

            'meta.newline' => new CloseRule(new RegexMatcher('/()\R/'), [
                'factory' => new TokenFactory(TerminatorToken::class),
                'context' => ['!operator.escape', 'string.single-line'],
                'closes'  => ['string.single-line.double', 'string.single-line.single']
            ]),

            'number' => new Rule(
                new RegexMatcher('/(-?\b(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?)\b/')
            ),

            'string' => [
                'single-line' => [
                    'double' => new Rule(new RegexMatcher('/(?:^|[^"])(")(?=[^"]|$)/'), [
                        'factory' => new TokenFactory(ContextualToken::class),
                        'context' => $standard,
                    ]),
                    'single' => new Rule(new RegexMatcher('/(?:^|[^\'])(\')(?=[^\']|$)/'), [
                        'factory' => new TokenFactory(ContextualToken::class),
                        'context' => $standard,
                    ]),
                ],
                'multi-line' => [
                    'double' => new Rule(new SubStringMatcher('"""'), [
                        'factory'  => new TokenFactory(ContextualToken::class),
                        'context'  => $standard,
                        'priority' => 2,
                    ]),
                    'single' => new Rule(new SubStringMatcher('\'\'\''), [
                        'factory'  => new TokenFactory(ContextualToken::class),
                        'context'  => $standard,
                        'priority' => 2,
                    ]),
                ]
            ],

            'symbol.function' => new Rule(new RegexMatcher('/def\s+([a-z_]\w+)\s*\(/i')),
            'symbol.class'    => new Rule(new RegexMatcher('/class\s+([a-z_]\w+)/i')),
        ]);
    }
773322
public function init()
    {
        parent::init();
        $that = $this;

        if ($this->owner instanceof Controller_Validator) {
            $this->owner->addHook('extraRules', array($this, 'extraRules'));

            return;  // no source, simply extend rules.
        }

        if ((
            $this->owner instanceof \Model ||
            $this->owner instanceof \Form

        ) && !$this->owner->hasMethod('is')) {
            $this->source = $this->owner; // must support set/get interface
            $this->owner->validator = $this;

            $this->source->addMethod('is', function ($m) use ($that) {
                $args = func_get_args();
                array_shift($args);

                call_user_func_array(array($that, 'is'), $args);
                $that->on('beforeSave', null, true);

                return $m;
            });
        }
    }
563118
public function validate(Request $request, array $rules = [], array $messages = [], array $customAttributes = [])
    {
        $rules = array_merge_recursive(config('forum.validation.rules'), $rules);

        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
    }
471401
public function setupRules()
    {
        parent::setupRules();

        $this->rules->remove('meta.declaration');
        $this->rules->remove('meta.declaration.media');

        $this->rules->add('meta.selector', new Rule(new RegexMatcher('/(?=(?:\n+|^)(\h*)([^\h].*)\n+\1\h+)/', [
            2 => Token::NAME
        ]), [
            'context'  => Validator::everywhere(),
            'priority' => 3,
            'factory'  => new TokenFactory(MetaToken::class)
        ]));

        $this->rules->add('meta.declaration', new Rule(new RegexMatcher('/\n((?:\h+.*?(?>\n|$)+)+)/'), [
            'context'  => Validator::everywhere(),
            'priority' => 2,
            'factory'  => new TokenFactory(MetaToken::class)
        ]));

        $this->rules->add('meta.declaration.media', new Rule(new RegexMatcher('/@media(.*?)\n/'), [
            'context' => Validator::everywhere(),
            'factory' => new TokenFactory(MetaToken::class)
        ]));

        $this->rules->add('symbol.selector.tag', new Rule(new RegexMatcher('/\b([a-z-][\w-]*)/'), [
            'context' => ['meta.selector', '!symbol', '!meta.declaration.media'],
        ]));

        $this->rules->rule('symbol.selector.class')->setContext(['meta.selector']);
        $this->rules->rule('keyword.at-rule')->setContext(['meta.selector']);
        $this->rules->rule('symbol.selector.class.pseudo')->setContext(['meta.selector']);
        $this->rules->rule('symbol.selector.id')->setContext(['meta.selector']);
    }
427691
public void validateAllFields() {

        CmsValidationController validationController = new CmsValidationController(
            m_fields.values(),
            createValidationHandler());
        validationController.setFormValidator(m_validatorClass);
        validationController.setFormValidatorConfig(createValidatorConfig());
        startValidation(validationController);
    }
690425
protected void registerValidatorAttributes() {
        // CustomValidator:
        addAttributeProcessor(new CustomValidatorLmlAttribute(), "validator", "validate", "method", "action", "check");
        // FormInputValidator:
        addAttributeProcessor(new ErrorMessageLmlAttribute(), "error", "errorMsg", "errorMessage", "formError");
        addAttributeProcessor(new HideOnEmptyInputLmlAttribute(), "hideOnEmpty", "hideErrorOnEmpty");
        // GreaterThanValidator:
        addAttributeProcessor(new GreaterOrEqualLmlAttribute(), "orEqual", "allowEqual", "greaterOrEqual");
        addAttributeProcessor(new GreaterThanLmlAttribute(), "value", "min", "greaterThan");
        // LesserThanValidator:
        addAttributeProcessor(new LesserOrEqualLmlAttribute(), "orEqual", "allowEqual", "lesserOrEqual");
        addAttributeProcessor(new LesserThanLmlAttribute(), "value", "max", "lesserThan");
        // FormValidator (VisFormTable):
        addAttributeProcessor(new FormSuccessMessageLmlAttribute(), "success", "successMsg", "successMessage");
        addAttributeProcessor(new TreatDisabledFieldsAsValidLmlAttribute(), "treatDisabledFieldsAsValid",
                "disabledValid");
        // FormValidator children:
        addAttributeProcessor(new DisableOnFormErrorLmlAttribute(), "disableOnError", "disableOnFormError",
                "formDisable");
        addAttributeProcessor(new ErrorMessageLabelLmlAttribute(), "errorMessage", "errorLabel", "errorMsgLabel",
                "errorMessageLabel");
        addAttributeProcessor(new RequireCheckedLmlAttribute(), "requireChecked", "formChecked", "notCheckedError",
                "uncheckedError");
        addAttributeProcessor(new RequireUncheckedLmlAttribute(), "requireUnchecked", "requireNotChecked",
                "formUnchecked", "checkedError");
    }
352154
public function validate(array $rules = array(), array $customMessages = array()) {
        if ($this->fireModelEvent('validating') === false) {
            if ($this->throwOnValidation) {
                throw new InvalidModelException($this);
            } else {
                return false;
            }
        }

        // check for overrides, then remove any empty rules
        $rules = (empty($rules))? static::$rules : $rules;
        foreach ($rules as $field => $rls) {
            if ($rls == '') {
                unset($rules[$field]);
            }
        }

        if (empty($rules)) {
            $success = true;
        } else {
			$customMessages = (empty($customMessages))? static::$customMessages : $customMessages;

			if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) {
				$this->fill(Input::all());
			}

			$data = $this->getAttributes(); // the data under validation

			// perform validation
			$validator = static::makeValidator($data, $rules, $customMessages);
			$success   = $validator->passes();

			if ($success) {
				// if the model is valid, unset old errors
				if ($this->validationErrors->count() > 0) {
					$this->validationErrors = new MessageBag;
				}
			} else {
				// otherwise set the new ones
				$this->validationErrors = $validator->messages();

				// stash the input to the current session
				if (!self::$externalValidator && Input::hasSession()) {
					Input::flash();
				}
			}
		}

        $this->fireModelEvent('validated', false);

	    if (!$success && $this->throwOnValidation) {
		    throw new InvalidModelException($this);
	    }

        return $success;
    }
766251
public function validateForm()
    {
        $validator = $this->getValidationFactory()->make(
            $this->requestData(),
            $this->rules()
        );

        if ($validator->fails())
            throw new \Exception($this->formatErrors($validator->errors()));
    }
805928
public function addValidator($rule, $callback)
    {
        $method = 'validate_'.$rule;

        if (method_exists(__CLASS__, $method) || isset($this->validation_methods[$rule])) {
            throw new Exception("Validator rule '$rule' already exists.");
        }

        $this->validation_methods[$rule] = $callback;

        return $this;
    }
763150
protected function validate(array $data, array $rules = null): void
    {
        $validator = $this->validatorFactory->make($data, $rules ?? $this->getValidationRules());
        if ($validator->fails()) {
            throw new ValidationException($validator);
        }
    }
310545
public synchronized void addRule(final RuleImpl rule) throws InvalidPatternException {
        final List<TerminalNode> terminals = this.ruleBuilder.addRule( rule,
                                                                       this.kBase );

        BaseNode[] nodes = terminals.toArray( new BaseNode[terminals.size()] );
        this.rules.put( rule.getFullyQualifiedName(), nodes );
        if (rule.isQuery()) {
            this.queries.put( rule.getName(), nodes );
        }
    }
837102
private function execute() {

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

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

				$file = $this -> getFile($rule -> field, $rule -> prefix);

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

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

						$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 -> setFile($file);
				$class -> setPrefix($rule -> prefix);
				$class -> setParameters($rule -> parameters);

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

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

			$this -> setExecuted(true);
		}
	}
79882
public function validate() {

		if ($this->getEndAction() === null) {
			throw new ValidationException("'endAction' can't be null", 'endAction', $this);
		}
		if ($this->getPlannedEndDate() === null) {
			throw new ValidationException("'plannedEndDate' can't be null", 'plannedEndDate', $this);
		}
		if ($this->getSubscription() === null) {
			throw new ValidationException("'subscription' can't be null", 'subscription', $this);
		}
	}
781516
function setRules (rules) {
    debug('set rules', rules)
    // require array
    assert.ok(Array.isArray(rules), 'rules array required')
    // add each rule
    _.each(rules, rule => this.setRule(rule))
}
963267
public void addValidation(Object key, Validation validation){
        initMapOnce();
        validations.put(key, validation);
        // update aggregated value
        passedAll = passedAll && validation.passed();
    }
479717
public void addRule (String description, String... extensions) {
		rules.add(new Rule(description, extensions));
	}