Add transition rules

array structure:
array( array(sourseState, input, targetState[, inputAction]),
array(sourseState, input, targetState[, inputAction]),
array(sourseState, input, targetState[, inputAction]),
...
)

@param array $rules
778809
public function addRules($rules)
    {
        foreach ($rules as $rule) {
            $this->addrule($rule[0], $rule[1], $rule[2], isset($rule[3])?$rule[3]:null);
        }
    }
1101211
function addRules(rules) {
        _.each(rules, function (rule) {
            _global.rules[rule.id] = rule;
        });
    }
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;
    }
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))
}
772661
public function applyRuleOptions($rules)
    {
        foreach ($rules as $key => $rule) {
            foreach ($this->_ruleOptions as $name => $value) {
                $rules[$key][$name] = $value;
            }
        }

        return $rules;
    }
453721
private function setAttributeRules(array $rules): self
    {
        assert($this->debugCheckIndexesExist($rules));

        $this->attributeRules = $rules;

        return $this;
    }
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;
    }
669067
private function setRule($rules)
    {
        $this->rules = array_merge_recursive(
            $this->rules, $this->explodeExplicitRule($rules)->rules
        );
    }
675205
protected function normalizeValidationRuleSourceDataFromConfig(array $rules)
    {
        // Remove entries to be ignored and excluded
        $filteredRules = array_filter($rules, function ($rule, $key) {

            return  false !== $rule
                &&  ! empty($rule)
                &&  ! (is_string($rule) && is_numeric($key));

        }, ARRAY_FILTER_USE_BOTH);

        return $this->normalizeValidationRuleSourceData($filteredRules);
    }
142742
public function add(\Caridea\Validate\Rule ...$rules): self
    {
        $this->rules = array_merge($this->rules, $rules);
        return $this;
    }
473489
public function addTransitions(array $transitions): self
    {
        $builder = clone $this;
        foreach ($transitions as $transition) {
            $builder = $this->addTransition($transition);
        }
        return $builder;
    }
544553
public function process(array $rules, array $data) {
        
        // If conditionning
        $this->rules[] = new Rule(
            'if_boolean', 
            'if:(\w+)', 
            '<?php if (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
        		'if_condition',
        		'if:(\w+)([!<>=]+)(\w+)',
        		'<?php if (isset($this->data[\'$1\'])){$base = $this->data[\'$1\'];}else{$base = \'$1\';};
        		if (isset($this->data[\'$3\'])){$value = $this->data[\'$3\'];}else{$value = \'$3\';}?>
        		<?php if ($base $2 $value): ?>'
        );
        $this->rules[] = new Rule(
            'ifnot', 
            'ifnot:(\w+)', 
            '<?php if (!isset($this->data[\'$1\']) || !$this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'else', 
            'else', 
            '<?php else: ?>'
        );
        $this->rules[] = new Rule(
            'elseif_boolean', 
            'else:(\w+)', 
            '<?php elseif (isset($this->data[\'$1\']) && $this->data[\'$1\']): ?>'
        );
        $this->rules[] = new Rule(
            'elseif_condition', 
            'else:(\w+)([!<>=]+)(\w+)', 
            '<?php elseif (((isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 $this->data[\'$3\']) ||
        		((isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && $this->data[\'$1\'] $2 \'$3\') ||
        		((!isset($this->data[\'$1\']) && isset($this->data[\'$3\'])) && \'$1\' $2 $this->data[\'$3\']) ||
        		((!isset($this->data[\'$1\']) && !isset($this->data[\'$3\'])) && \'$1\' $2 \'$3\')): ?>'
        );
        $this->rules[] = new Rule(
            'endif', 
            'endif', 
            '<?php endif; ?>'
        );
        
        // Loops
        $this->rules[] = new Rule(
            'loop', 
            'loop:(\w+)', 
            '<?php foreach ($this->data[\'$1\'] as $element): $this->wrap($element); ?>'
        );
        $this->rules[] = new Rule(
            'endloop', 
            'endloop', 
            '<?php $this->unwrap(); endforeach; ?>'
        );
        
        // Importing
        $this->rules[] = new Rule(
            'import_view', 
            'import:(([^\/\s]+\/)?(.*))', 
            '<?php echo $this->importFile(\'$1\'); ?>'
        );
        
        // Clean variables
        $this->rules[] = new Rule(
            'escape_var', 
            'escape:(\w+)', 
            '<?php $this->showVariable(\'$1\', true); ?>'
        );
        
        // Custom rules
        $this->rules = array_merge($this->rules, $rules);
        
        // Variables
        $this->rules[] = new Rule(
            'variable', 
            '(\w+)', 
            '<?php $this->showVariable(\'$1\'); ?>'
        );
        
        // Arrays
        $this->rules[] = new Rule(
        		'variable_array',
        		'(\w+)\[(\w+)\]',
        		'<?php echo (isset($this->data[\'$1\'][\'$2\'])) ? $this->data[\'$1\'][\'$2\'] : "&#123;$1[$2]&#125"; ?>'
        );
        
        $this->rules[] = new Rule(
        		'variable_array_escape',
        		'escape:(\w+)\[(\w+)\]',
        		'<?php echo htmlentities($this->showVariable(\'$1\')[\'$2\']); ?>'
        );
        
        $this->data = $data;
        $this->stack = array();
        
        foreach ($this->rules as $rule) {
            $this->template = preg_replace('/\{' . $rule->rule() . '\}/', $rule->replacement(), $this->template);
        }
        
        $this->template = '?>' . $this->template;
        
        ob_start();
        eval($this->template);
        return ob_get_clean();
    }
615276
private function setRuleset(array $rules = [])
    {
        // Passed rules rule, but we will use model rules if nothing has been passed
        $this->rules = $this->ruleset = $this->selectRules($rules);

        // Expand out rules
        foreach ($this->rules as $field => &$rule)
        {
            // Change pipe delimited rules to arrays
            $set = $this->pipeToArray($rule);
            $rule = $this->processRuleset($field, $set);
        }
    }
937391
private function setToManyIndexes(array $rules): self
    {
        assert($this->debugCheckIndexesExist($rules));

        $this->toManyRules = $rules;

        return $this;
    }
692859
public function mapFieldsRules(array $rules)
    {
        foreach ($rules as $field => $rule) {
            $this->mapFieldRules($field, $rule);
        }
    }
144876
public function validationRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->validationRules;
        }

        $this->validationRules = $rules;

        return $this;
    }
996036
public function setRules(array $rules)
    {
        foreach ($rules as $key => $values) {

            if ((is_array($values) === true && empty($values) === false) || is_callable($values)) {
                $this->rules[$key] = $values;
            } else {
                $this->rules[$key] = trim($values);
            }
        }

        return $this;
    }