createRule

@param string            $rule
@param \SplPriorityQueue $namespaces

@return  ValidatorInterface
965804
public static function create($rule, \SplPriorityQueue $namespaces = null)
    {
        if (!$rule) {
            return new NoneValidator();
        }

        if (class_exists($rule)) {
            return new $rule();
        }

        $namespaces = $namespaces ?: static::getNamespaces();

        foreach ($namespaces as $namespace) {
            $class = $namespace . '\\' . ucfirst($rule) . 'Validator';

            if (class_exists($class)) {
                return new $class();
            }
        }

        if (is_string($rule)) {
            return new RegexValidator($rule);
        }

        throw new \InvalidArgumentException(sprintf('Validator %s is not exists.', $rule));
    }
768047
public function validateRule(Rule $rule, array $restrictions = array())
    {
        /** @var \Claroline\CoreBundle\Rule\Constraints\AbstractConstraint[] $usedConstraints */
        $usedConstraints = array();
        $existedConstraints = $this->getConstraints();

        foreach ($existedConstraints as $existedConstraint) {
            if ($existedConstraint->isApplicableTo($rule)) {
                $usedConstraints[] = $existedConstraint->setRule($rule);
            }
        }

        $validatedConstraints = 0;
        $nbConstraints = count($usedConstraints);

        $associatedLogs = $this->getAssociatedLogs($usedConstraints, $restrictions);

        foreach ($usedConstraints as $usedConstraint) {
            $usedConstraint->setAssociatedLogs($associatedLogs);

            if ($usedConstraint->validate()) {
                ++$validatedConstraints;
            }
        }

        return ($validatedConstraints === $nbConstraints) ? $associatedLogs : false;
    }
184514
public function validate($data, array $rules, $context = null): ValidatorInterface
    {
        return new Validator($data, $rules, $context, $this);
    }
132203
public function addRule( ADT_CSS_Rule $rule ){
		$got = $this->getRuleBySelector( $rule->selector );
		if( $got )
			foreach( $rule->getProperties() as $property )
				$got->setPropertyByKey( $property->getKey(), $property->getValue() );
		else{
			if( !preg_match( '/([a-z])|(#|\.[a-z])/i', $rule->getSelector() ) )
				throw new InvalidArgumentException( 'Invalid selector' );
			$this->rules[]	= $rule;
		}
	}
1351997
private function enforceRule(array $rule)
    {
        if (
            !isset($rule[0])
            || !in_array($rule[0], ['allow', 'deny'])
        ) {
            throw new InvalidAclRuleException("Invalid ACL rule");
        }
        $rule = array_merge($this->getEmptyRule(), $rule);
        $ruleType = $rule[0];
        $this->acl->{$ruleType}($rule['roles'], $rule['resources'], $rule['privileges'], $rule['assert']);
    }
14343
public function add_rule( $name, $rules ) {
		$parsed = ( new Validation_Parser() )->parse( $rules );

		foreach ( $parsed as $rule ) {
			$this->rule( $rule[0], $name, ...$rule[1] );
		}

		return $this;
	}
755224
public function addRule(RuleAbstract $rule)
    {
        // TODO Keyframes with duplicate identifiers do NOT cascade!
        // Last one overwrites previous ones.
        // @see https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes#Duplicate_resolution

        if ($rule instanceof KeyframesRuleSet) {
            $this->rules[] = $rule;
        } else {
            throw new \InvalidArgumentException(
                "Invalid rule instance. Instance of 'KeyframesRuleSet' expected."
            );
        }

        return $this;
    }
891537
public function validateUniques(array $rules = array(), array $customMessages = array()) {
		$rules = $this->buildUniqueExclusionRules($rules);
		return $this->validate($rules, $customMessages);
	}
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 );
        }
    }
283528
public function rule($name, $rule = '')
    {
        if (is_array($name)) {
            $this->rule = $name + $this->rule;
            if (is_array($rule)) {
                $this->field = array_merge($this->field, $rule);
            }
        } else {
            $this->rule[$name] = $rule;
        }

        return $this;
    }
797374
public static function create($field, \SplPriorityQueue $namespaces = null)
    {
        if ($field instanceof \SimpleXMLElement) {
            $field = static::createByXml($field, $namespaces);
        } elseif (is_string($field) && class_exists($field)) {
            $field = new $field();
        } elseif (is_string($field)) {
            $xml = new \SimpleXMLElement($field);

            $field = static::createByXml($xml, $namespaces);
        } elseif (!($field instanceof AbstractField)) {
            throw new \InvalidArgumentException(
                'Windwalker\\Form\\Form::addField() need AbstractField or SimpleXMLElement.'
            );
        }

        return $field;
    }
1169667
public function rule($rule, $fields, ...$params)
    {
        if (\is_callable($rule)
            && !(\is_string($rule) && $this->hasValidator($rule))
        ) {
            $name = $this->getUniqueRuleName($fields);
            $message = $params[0] ?? null;
            $this->addInstanceRule($name, $rule, $message);
            $rule = $name;
        }

        $errors = $this->getRules();
        if (!isset($errors[$rule])) {
            $ruleMethod = 'validate' . \ucfirst($rule);
            if (!\method_exists($this, $ruleMethod)) {
                throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
            }
        }

        // Ensure rule has an accompanying message
        $messages = $this->getRuleMessages();
        $message = $messages[$rule] ?? self::ERROR_DEFAULT;

        // Ensure message contains field label
        if (\strpos($message, '{field}') === false) {
            $message = '{field} ' . $message;
        }

        $this->_validations[] = [
            'rule' => $rule,
            'fields' => (array) $fields,
            'params' => (array) $params,
            'message' => '{field} ' . $message,
            'skip' => self::SKIP_CONTINUE,
        ];

        return $this;
    }
1178546
public static function validator(array $rules = [], ContainerInterface $container = null): self
    {
        $validator = new static($rules, $container);

        return $validator;
    }
142742
public function add(\Caridea\Validate\Rule ...$rules): self
    {
        $this->rules = array_merge($this->rules, $rules);
        return $this;
    }
628408
public static function make($data, array $rules, array $customMessages = [], array $attributes = [])
    {
        return new Validator($data, $rules, $customMessages, $attributes);
    }
30835
public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->isUnique(['name']));

        // don't allow deletion of non-deletable menu
        $rules->addDelete(function ($entity, $options) {
            return !$entity->deny_delete;
        }, 'systemCheck');

        return $rules;
    }
1156366
public function setupRules()
    {
        $this->rules->addMany([
            'tag.open'  => [
                new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')),
                new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']])
            ],
            'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')),

            'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'constant.entity' => new Rule(new RegexMatcher('/(&(?:\#\d+|[a-z])+;)/si')),

            'comment' => new Rule(new CommentMatcher(null, [['<!--', '-->']])),
            'string'  => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['tag']]),
        ]);
    }