Extract the rule name and parameters from a rule.

@param string $rule
@return array
16531
private function parseRule($rule)
    {
        $parameters = [];

        if (strpos($rule, ':') !== false) {
            list($rule, $parameter) = explode(':', $rule, 2);
            $parameters = $this->parseParameters($rule, $parameter);
        }

        if (!Variable::ruleExists($rule)) {
            throw new \InvalidArgumentException("validation: rule '$rule' not supported.");
        }

        return [$rule, $parameters];
    }
1211122
public function findByKey($rule){

            $r = [];

            foreach($this->data as $k=>$v){
                if($rule($k)){
                    $r[] = $this->{$k};
                }
            }

            return $r;

        }
291188
protected function compileReplace(array $rule)
    {
        return array(
            'regexp' => '([' .
                preg_quote($this->compileCharacter($rule['data']['srcStart'])) . '-' .
                preg_quote($this->compileCharacter($rule['data']['srcEnd'])) .
                '])us',
            'callback' => $this->compileTargetCharacter($rule['data']['dest']),
        );
    }
472246
protected function removeRule($rule)
    {
        if (!is_string($this->rules)) {
            return;
        }

        $pattern = "/{$rule}[^\|]?(\||$)/";
        $this->rules = preg_replace($pattern, '', $this->rules, -1);
    }
1041005
protected function getRulesNames(AllOf $rules): array
    {
        $rulesNames = [];
        foreach ($rules->getRules() as $rule) {
            try {
                $rulesNames[] = lcfirst((new ReflectionClass($rule))->getShortName());
            } catch (ReflectionException $e) {
            }
        }

        return $rulesNames;
    }
370448
public function getRuleProperties(AbstractRule $rule)
    {
        $properties = array();
        if (!is_null($rule->getService())) {
            $service = $this->container->get($rule->getService());
            if ($service instanceof RuleServiceInterface) {
                $properties = $service->getJsProperties($rule);
            }
        }

        return array_merge($rule->getJsProperties(), $properties);
    }
483030
protected function extractInputFromRules($data, array $rules): array
    {
        if (\is_object($data)) {
            $data = (array)$data;
        }

        $result = [];
        $additional = [];
        $arrays = [];
        $isGlobalArray = false;

        foreach ($rules as $rule => $value) {
            if (Str::contains($rule, '.')) {
                $attributes = explode('.', $rule);
                $rule = array_shift($attributes);
                $key = implode('.', $attributes);

                if (\is_array($data)) {
                    if (array_key_exists($rule, $data)) {
                        $additional[$rule][$key] = $value;
                    } elseif ($rule === '*') {
                        $arrays[$key] = $value;
                    }
                }
            } elseif (\is_array($data) && array_key_exists($rule, $data)) {
                $result[$rule] = $data[$rule];
            } elseif ($rule === '*' && \is_array($data)) {
                $isGlobalArray = true;
            }
        }

        if (!empty($arrays)) {
            $result = [];
            foreach ($data as $item) {
                $result[] = $this->extractInputFromRules($item, $arrays);
            }

            return $result;
        } elseif ($isGlobalArray) {
            return $data;
        }

        foreach ($additional as $key => $item) {
            $result[$key] = $this->extractInputFromRules($data[$key], $item);
        }

        return $result;
    }
776659
private function getRuleClass($rule) {

		if(false === is_string($rule)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
		}

		if(true === isset($this -> custom[$rule])) {
			return $this -> custom[$rule];
		}

		return __NAMESPACE__ . self :: NAMESPACE_RULES . ucfirst(strtolower($rule));
	}
920918
protected function parseStringRule($rules)
    {
        $parameters = [];

        // 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($rules, ':') !== false) {
            list($rules, $parameter) = explode(':', $rules, 2);

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

        return [studly_case(trim($rules)), $parameters];
    }
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];
    }
388275
protected function extractCustomValidationShortName(array $rules)
    {
        $customRules = array_map(function ($rule) {
            $fullname = $this->getCustomRuleFullName($rule);

            if ($this->canHaveUsingCommand($fullname)) {
                $shortName = $this->getCustomRuleShortName($fullname);

                return $this->makeCustomRuleCall($shortName);
            }

            return $this->makeCustomRuleCall($fullname);

        }, $rules);

        return $customRules;
    }
1293974
private function explodeCleanParamRule($rule)
    {
        // strip multi-spaces
        $rule = preg_replace('/\s+/S', ' ', $rule);
        // split into parameter and path
        $array = explode(' ', $rule, 2);
        $cleanParam = array();
        // strip any invalid characters from path prefix
        $cleanParam['path'] = isset($array[1]) ? $this->encode_url(preg_replace('/[^A-Za-z0-9\.-\/\*\_]/', '', $array[1])) : '/*';
        $param = explode('&', $array[0]);
        foreach ($param as $key) {
            $cleanParam['param'][] = trim($key);
        }
        return $cleanParam;
    }
1285885
protected static function convertPartialMatchRule($rule)
  {
    /** @var RPartialMatchRule $convertedRule */
    $convertedRule = null;
    if (!empty($rule)) {
      $convertedRule = new RPartialMatchRule();
      $convertedRule->setTerms($rule->getTerms())
          ->setTermsGreaterThan($rule->getTermsGreaterThan())
          ->setMustMatch($rule->getMustMatch())
          ->setPercentage($rule->isPercentage());
    }
    return $convertedRule;
  }
1338720
protected function explodeRules($rules)
    {
        foreach ($rules as $key => $rule) {
            $rules[$key] = is_string($rule) ? explode('|', $rule) : $rule;
        }

        return $rules;
    }
173659
public function getRule($rule, $domain = null)
    {
        if (is_null($domain)) {
            $domain = $this->domain;
        }

        return $this->app['rule_name']->getRule($rule, $domain);
    }
191180
protected function extractCustomValidationNamespaces(array $rules)
    {
        $customRules = array_filter($rules, function ($rule) {
            $fullname = $this->getCustomRuleFullName($rule);

            return $this->canHaveUsingCommand($fullname);
        });

        $customRules = array_map(function ($rule) {
            return $this->getCustomRuleFullName($rule);
        }, $customRules);

        return array_unique($customRules);
    }
728138
protected function getRule($rule)
    {
        $set = $this->rules[$rule];

        if (count($set) != 2) {
            throw new LengthException($this->translate(
                'Invalid "{rule}" rule. Rule should be in format: [NAME, N].',
                ['rule' => $rule]
            ));
        }

        return $set;
    }