Parse a string to array of formatted rules.

@param  string $rules

@return array
16959
public function parse($rules)
    {
        $this->rules = $rules;
        $parsed = [];
        foreach ($this->getRules() as $rulesArray) {
            $column = $this->getColumn($rulesArray);
            $attributes = $this->getAttributes($column, $rulesArray);
            $parsed[$column] = $attributes;
        }

        return $parsed;
    }
1320055
public function optimize(array $rules): array
    {
        assert(empty($rules) === false);

        $ruleId       = 0;
        $rawTargets   = [];
        $encodedRules = [];
        foreach ($rules as $rule) {
            /** @var RuleInterface $rule */
            $rawTargets[$ruleId]   = $rule->getTarget();
            $encodedRules[$ruleId] = Encoder::encodeRule($rule);
            $ruleId++;
        }

        $callable         = static::METHOD;
        $optimizedTargets = $this->optimizeTargets($rawTargets);

        /** @var callable|array $callable */
        assert($callable !== null && is_array($callable) === true &&
            is_callable($callable) === true && count($callable) === 2 &&
            is_string($callable[0]) === true && is_string($callable[1]) === true);

        return [
            static::INDEX_TARGETS  => $optimizedTargets,
            static::INDEX_RULES    => $encodedRules,
            static::INDEX_CALLABLE => $callable,
        ];
    }
547500
public function filterRules($rules)
    {
        foreach ($this->_behaviors as $name => $foo) {
            if (($behavior = $this->getBehavior($name)) instanceof \nineinchnick\usr\components\FormModelBehavior) {
                $rules = $behavior->filterRules($rules);
            }
        }

        return $rules;
    }
1181399
protected function parseRule($rule)
	{
		$parameters = array();

		// The format for specifying validation rules and parameters follows an
		// easy {rule}:{parameters} formatting convention. For instance the
		// rule "Max:3" states that the value may only be three letters.
		if (strpos($rule, ':') !== false)
		{
			list($rule, $parameter) = explode(':', $rule, 2);

			$parameters = $this->parseParameters($rule, $parameter);
		}

		return array(studly_case($rule), $parameters);
	}
890574
public function explode( $rules ) {
		if ( empty( $rules ) ) {
			return [];
		}

		foreach ( $rules as $key => $_rules ) {
			$rules[ $key ] = $this->parse( $_rules );
		}

		return $rules;
	}
1019941
protected function parseArrayRule(array $rules)
    {
        $rule = Arr::get($rules, 0);

        return array(
            Str::studly(trim($rule)), array_slice($rules, 1)
        );
    }
1179020
protected function getRule($attribute, $rules)
    {
        if (! array_key_exists($attribute, $this->rules)) {
            return;
        }

        $rules = (array) $rules;

        foreach ($this->rules[$attribute] as $rule) {
            [$rule, $parameters] = ValidationRuleParser::parse($rule);

            if (in_array($rule, $rules)) {
                return [$rule, $parameters];
            }
        }
    }
764031
public function filterRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->filterRules;
        }

        $this->filterRules = $rules;

        return $this;
    }
126646
public static function parse_css_rules( array $rules ) {

		ob_start();

		foreach ( $rules as $rule => $properties ) {

			printf(
				"%s {\n",
				implode( ",\n", array_map( 'trim', explode( ',', $rule ) ) )
			);

			foreach ( $properties as $property => $value ) {

				printf( "\t%s: %s;\n", $property, $value );

			}

			echo "}\n";

		}

		return ob_get_clean();

	}
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);
    }
772661
public function applyRuleOptions($rules)
    {
        foreach ($rules as $key => $rule) {
            foreach ($this->_ruleOptions as $name => $value) {
                $rules[$key][$name] = $value;
            }
        }

        return $rules;
    }
209672
static protected function parseRule($rule)
    {
        switch (gettype($rule)) {
            case 'string':
                $type = $rule;
                $target = null;
                $types = [];
                break;
            case 'array':
                $type = isset($rule['type']) ? $rule['type'] : [];
                $target = isset($rule['target']) ? $rule['target'] : [];
                $types = isset($rule['types']) ? $rule['types'] : [];
                break;
            case 'object':
                $type = isset($rule->type) ? $rule->type : null;
                $target = isset($rule->target) ? $rule->target : null;
                $types = isset($rule->types) ? $rule->types : [];
                break;
            default:
                $type = null;
                $target = null;
                $types = [];
        }
        return compact('type', 'target', 'types');
    }
876945
protected function extractCustomValidationRules(array $rules)
    {
        $customRules = array_filter($rules, function ($rule) {
            return $this->isCustomRule($rule);
        });

        return $customRules;
    }
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();
    }
652283
protected function splitTypeAndProperties($rule)
    {
        // A nested rule
        if (!mb_strpos($rule, ':[')) {
            $parts = explode('|', $rule);
            $typeName = array_shift($parts);
            return [$typeName, $parts];
        }

        $chars = Helper::stringSplit($rule);

        $level = 0;
        $isFirst = true;
        $typeName = '';
        $parts = [];
        $currentPart = -1;

        foreach ($chars as $char) {
            if ($char == '[') {
                $level++;
            }

            if ($char == ']') {
                $level--;
            }

            if ($char == '|' && $level == 0) {
                $isFirst = false;
                $currentPart++;
                continue;
            }

            if ($isFirst) {
                $typeName .= $char;
                continue;
            }


            if (!isset($parts[$currentPart])) {
                $parts[$currentPart] = '';
            }

            $parts[$currentPart] .= $char;
        }

        return [$typeName, $parts];
    }
1053397
public function parse($value, $rule) {
        $rs = $value;

        if (!is_array($rs)) {
            $ruleFormat = !empty($rule['format']) ? strtolower($rule['format']) : '';
            if ($ruleFormat == 'explode') {
                $rs = explode(isset($rule['separator']) ? $rule['separator'] : ',', $rs);
            } else if ($ruleFormat == 'json') {
                $rs = json_decode($rs, TRUE);

                if (!empty($value) && $rs === NULL) {
                    $message = isset($rule['message']) 
                        ? \PhalApi\T($rule['message']) 
                        : \PhalApi\T('{name} illegal json data', array('name' => $rule['name']));
                    throw new BadRequestException($message);
                }
            } else {
                $rs = array($rs);
            }
        }

        $this->filterByRange(count($rs), $rule);

        return $rs;
    }
1232010
protected function parseValidationRule($rule)
	{
		$ruleArray = ['name' => '', 'parameters' => []];

		$explodedRule = explode(':', $rule);
		$ruleArray['name'] = array_shift($explodedRule);
		$ruleArray['parameters'] = explode(',', array_shift($explodedRule));

		return $ruleArray;
	}