Merges all field's rules into one
if you have elegant implementation, you are welcome.

@param array $rules

@return array
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;
    }
553897
protected function indexRules(array $rules)
    {        
        $this->indexedRules = array();
        
        foreach($rules as $rule){
            if(isset($this->indexedRules[$rule[self::LOOKUP_CHAR]])){
                $this->indexedRules[$rule[self::LOOKUP_CHAR]][] = $rule;
            } else {
                $this->indexedRules[$rule[self::LOOKUP_CHAR]] = array($rule);
            }
        }       
    }
666752
private function setupRules($rules)
    {
        // prepares filter for requiredIf
        $rules = Utils\HelperRequiredIf::prepare($this, $rules);

        // prepares filter for sameWith.
        $rules = Utils\HelperSameWith::prepare($this, $rules);

        return $rules;
    }
156239
public function mergeRules( $attribute, $rules = [] )
	{
		if ( is_array( $attribute ) )
		{
			foreach ( $attribute as $innerAttribute => $innerRules )
				$this->mergeRulesForAttribute( $innerAttribute, $innerRules );

			return $this;
		}

		return $this->mergeRulesForAttribute( $attribute, $rules );
	}
513981
public function addRules(array $rules)
    {
        foreach ($rules as $character => $replacement) {
            $this->addRule($character, $replacement);
        }

        return $this;
    }
500197
protected function parseRule( $rules )
	{
		if ( is_array( $rules ) )
		{
			$rules = $this->parseArrayRule( $rules );
		}
		else
		{
			$rules = $this->parseStringRule( $rules );
		}

		$rules[0] = $this->normalizeRule( $rules[0] );

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

        $this->rules = [];

        $this->addRules($rules);

        return $this;
    }
772661
public function applyRuleOptions($rules)
    {
        foreach ($rules as $key => $rule) {
            foreach ($this->_ruleOptions as $name => $value) {
                $rules[$key][$name] = $value;
            }
        }

        return $rules;
    }
960899
public function rules($rules)
    {
        foreach ($rules as $rule => $field) {
            if (is_array($field) && is_array($field[0])) {
                foreach ($field as $params) {
                    array_unshift($params, $rule);
                    call_user_func_array([$this, 'rule'], $params);
                }
            } else {
                $this->rule($rule, $field);
            }
        }
        return $this;
    }
25048
protected function prepareRules(array $rules)
    {
        // Prepared rules container
        $preparedRules = [];

        foreach ($rules as $key => $tests) {
            // Support arrays and pipes-splitted cases
            $tests = ! is_array($tests) ? explode('|', $tests) : $tests;

            // Prepared tests container
            $preparedTests = [];

            foreach ($tests as $test) {
                // If validation variable exists in
                // our variables array we'll replace it.
                $test = str_replace(array_keys($this->variables), array_values($this->variables), $test);

                // Sometimes we expect a validation variable
                // but it's not present in our variables array
                // so we need to replace it with "null"
                $test = preg_replace('|{:.*}|is', 'null', $test);

                // Add test to container
                $preparedTests[] = $test;
            }

            // Add rule to container
            $preparedRules[$key] = $preparedTests;
        }

        return $preparedRules;
    }
918082
private function sortRules(&$rules)
    {
        sort($rules);
        usort($rules, function ($a, $b) {
            return strlen($a) - strlen($b);
        });
    }
1205089
public function rules($field, array $rules)
    {
        foreach ($rules as $rule)
        {
            $this->rule($field, $rule[0], Arr::get($rule, 1));
        }

        return $this;
    }
72809
private function getRules($rules)
    {
        $rules = [];

        foreach($rules as $rule)
        {
            $rules[] = explode('/', $rule);
        }

        return $rules;
    }
916341
public function rewrite_rules_array( array $rules ){
        if( !empty($this->rewrites) ){
            $rules = array_merge($this->rewrites, $rules);
        }
        return $rules;
    }
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;
    }
144513
private function explodeExplicitRule($rules)
    {
        foreach ($rules as $key => &$rule) {
            if (is_array($rule)) {

            }elseif($rule instanceof \Closure){
                $rule = [$rule];
            }else{
                $rule = explode("|", $rule);
            }
        }
        return (object) [
            'rules' => $rules
        ];
    }
1167171
protected function getValidationRulesFromElements(array $rules = [])
    {
        $this->getElements()->onlyActive()->each(function ($element) use (&$rules) {
            $element = $this->getElementContainer($element);

            if ($element instanceof Validable) {
                $rules += $element->getValidationRules();
            }
        });

        return $rules;
    }