Adds current rule options to the given set of rules.
@param  array $rules
@return array
772661
public function applyRuleOptions($rules)
    {
        foreach ($rules as $key => $rule) {
            foreach ($this->_ruleOptions as $name => $value) {
                $rules[$key][$name] = $value;
            }
        }

        return $rules;
    }
739717
public function addRule( $rule )
    {
        if ( ! ( $rule instanceof RuleStructure ) )
        {
            $rule = new RuleStructure( $rule );
        }

        $this->rules[] = $rule;
        return $this;
    }
263133
private function replaceBindings($rules)
	{

		// If we have no bindings we can just return the rules
		if (empty($this->bindings))
		{
			return $rules;
		}

		// Get any global bindings to merge into all bindings
		// Global bindings allow binding values to all the rules
		$globalBinding = $this->getGlobalBindings();

		foreach ($rules as $field => $rule)
		{
			// Field specific bindings
			$bindings = $this->getBindings($field);

			// Merge global bindings
			if ( ! empty($globalBinding))
			{
				$bindings = $bindings + $globalBinding;
			}

			foreach ($bindings as $key => $value)
			{
				$token = $this->tokenPrefix.$key.$this->tokenSuffix;

				if (is_array($rule))
				{

					// Handle array type rule sets
					$rule = array_map(function($v) use ($value, $token) {

						return str_replace($token, $value, $v);

					}, $rule);

				}
				else {

					// Handle piped style rule set
					$rule = str_replace($token, $value, $rule);

				}
			}

			// Set field rule
			$rules[$field] = $rule;
		}

		return $rules;
	}
799885
public function rules(array $rules)
    {
        foreach ($rules as $ruleType => $params) {
            if (\is_array($params)) {
                foreach ($params as $innerParams) {
                    $innerParams = (array) $innerParams;
                    $this->rule($ruleType, ...$innerParams);
                }
            } else {
                $this->rule($ruleType, $params);
            }
        }

        return $this;
    }
1189930
public function addRules(array $rules, $ruleset = null)
    {
        if ($ruleset) {
            $newRules = array_merge($this->getRuleset($ruleset), $rules);
            $this->setRuleset($newRules, $ruleset);
        } else {
            $newRules = array_merge($this->getRules(), $rules);
            $this->setRules($newRules);
        }
    }
800614
protected function parse_array_rules( array $rules ) {
		$parse_rules = [];

		foreach ( $rules as $key => $value ) {
			if ( is_int( $key ) ) {
				$parse_rules[] = [ $this->normalize( $value ), [] ];
				continue;
			}

			$key = $this->normalize( $key );

			if ( ! is_array( $value ) ) {
				$value = [ $value ];
			}

			$parse_rules[] = [ $key, $this->wrap_parameters( $key, $value ) ];
		}

		return $parse_rules;
	}
827692
public function parse($rules): Rule\Set
    {
        $isArray = is_array($rules);
        $isAssoc = $isArray && self::isAssociative($rules);
        $set = null;
        if (is_string($rules) || is_object($rules) || $isAssoc) {
            $set = $this->getRule($rules);
        } elseif ($isArray) {
            foreach ($rules as $v) {
                $toAdd = $this->getRule($v);
                $set = $set === null ? $toAdd : $set->merge($toAdd);
            }
        }
        return $set ?? new Rule\Set();
    }
153330
public function addRules(array $rules): array
    {
        // serialize the rules altogether

        $this->getSerializer()->clearBlocksWithStart()->clearBlocksWithEnd();

        $indexes = [];
        foreach ($rules as $name => $rule) {
            assert($rule instanceof RuleInterface);

            $ruleName = $rule->getName();
            if (empty($ruleName) === true) {
                $ruleName = $name;
            }

            $block          = $rule->setName($ruleName)->enableCapture()->toBlock();
            $indexes[$name] = $this->getSerializer()->addBlock($block);
        }

        $ruleIndexes = [
            static::RULES_ARRAY_INDEXES       => $indexes,
            static::RULES_ARRAY_START_INDEXES => $this->getSerializer()->getBlocksWithStart(),
            static::RULES_ARRAY_END_INDEXES   => $this->getSerializer()->getBlocksWithEnd(),
        ];

        $this->getSerializer()->clearBlocksWithStart()->clearBlocksWithEnd();

        // sometimes (e.g. update in relationship) an individual validation rule is needed
        // so we should have a second serialization of each rule individually

        $individualRules = [];
        foreach ($rules as $name => $rule) {
            $individualRules[$name] = $this->addRule($rule);
        }
        $ruleIndexes[static::RULES_ARRAY_SINGLE_INDEXES] = $individualRules;

        return $ruleIndexes;
    }
96729
public function explode($rules)
    {
        $this->implicitAttributes = [];

        $rules = $this->explodeRules($rules);

        return (object) [
            'rules' => $rules,
            'implicitAttributes' => $this->implicitAttributes,
        ];
    }
96051
public function mergeRules(array $rules)
    {
        $this->extendedRules = array_merge($this->extendedRules, $rules);
        $this->parsedRules = null;
        return $this;
    }
577769
public function parse($rules)
    {
        $attributes = array();
        $rules = $rule = $this->getRulesAsArray($rules);

        foreach ($rules as $rule) {
            list($rule, $parameters) = $this->parseRule($rule);

            if ($rule && method_exists($this, $rule)) {
                $attributes += $this->$rule($parameters);
            }
        }

        return $attributes;
    }
1302282
public function addRules($rules)
    {
        if ($rules instanceof RiskyRulesAwareInterface && $rules->isRisky()) {
            $this->setRiskyAllowed(true);
        }

        if ($rules instanceof \Traversable) {
            $rules = iterator_to_array($rules);
        }

        if (!is_array($rules)) {
            throw new \InvalidArgumentException('Expected rules to be an iterable.');
        }

        $rules = array_replace($this->getRules(), $rules);

        $this->setRules($rules);

        return $this;
    }
1284206
public function setRules( $rules )
    {
        $this->rules = array();

        foreach ( $rules as $rule )
        {
            $this->addRule( $rule );
        }

        return $this;
    }
122077
public function get_rule( array $rules ) {
		$logical = static::LOGICAL_AND;

		if ( static::is_group_rules( $rules ) ) {
			list( $logical, $rules ) = $this->parse_group_logical( $rules );
		}

		return $this->create_rule( $rules, $logical );
	}
628285
public static function getRulePos($rules) {
		$result = 1;
		$before = array();
		$after  = array();

		foreach($rules as $key => $val) {
			if($key == '<module:\w+>/<controller:\w+>/<action:\w+>')
				break;
			$result++;
		}

		$i = 1;
		foreach($rules as $key => $val) {
			if($i < $result)
				$before[$key] = $val;
			elseif($i >= $pos)
				$after[$key]  = $val;
			$i++;
		}

		return array('after' => $after, 'before' => $before);
	}
456461
public function add(array $conditions)
    {
        $this->conditions = array_merge($this->conditions, $conditions);

        return $this->conditions;
    }
760914
private static function prepareRules(array $rules)
    {
        $mergedRules = [];

        foreach ($rules as $ruleFields => $ruleConditions) {

            //if set of fields like 'firstname, lastname...'
            if (strpos($ruleFields, ',') !== false) {
                foreach (explode(',', $ruleFields) as $fieldName) {
                    $fieldName = trim($fieldName);

                    if (!isset($mergedRules[$fieldName])) {
                        $mergedRules[$fieldName] = $ruleConditions;
                    } else {
                        $mergedRules[$fieldName] .= '|'.$ruleConditions;
                    }
                }
            } else {
                if (!isset($mergedRules[$ruleFields])) {
                    $mergedRules[$ruleFields] = $ruleConditions;
                } else {
                    $mergedRules[$ruleFields] .= '|'.$ruleConditions;
                }
            }
        }

        $finalRules = [];

        //remove duplicated rules, like 'required|alpha|required'
        foreach ($mergedRules as $newRule => $rule) {
            $finalRules[$newRule] = implode('|', array_unique(explode('|', $rule)));
        }

        return $finalRules;
    }