src/RulesParser.php
public function parseRulesDefinition($definition): RulesCollection
    {
        if (is_callable($definition)) {

            $definition = [$definition];

        }

        if (is_string($definition)) {

            $definition = array_map('trim', explode('|', $definition));

        }

        if (is_array($definition)) {

            $keys = array_keys($definition);

            return array_reduce($keys, function ($rules, $key) use ($definition) {

                $definition = $definition[$key];

                $rule = $this->parseRuleDefinition($key, $definition);

                return $rules->withRule($rule);

            }, new RulesCollection);

        }

        throw new InvalidRuleFormatException($definition);
    }
public function parseRulesDefinition($definition): RulesCollection
    {
        if (is_callable($definition)) {

            $definition = [$definition];

        }

        if (is_string($definition)) {

            $definition = array_map('trim', explode('|', $definition));

        }

        if (is_array($definition)) {

            $keys = array_keys($definition);

            return array_reduce($keys, function ($rules, $key) use ($definition) {

                $definition = $definition[$key];

                $rule = $this->parseRuleDefinition($key, $definition);

                return $rules->withRule($rule);

            }, new RulesCollection);

        }

        throw new InvalidRuleFormatException($definition);
    }
public function parseRulesDefinition ( $ definition ) : RulesCollection { if ( is_callable ( $ definition ) ) { $ definition = [ $ definition ] ; } if ( is_string ( $ definition ) ) { $ definition = array_map ( 'trim' , explode ( '|' , $ definition ) ) ; } if ( is_array ( $ definition ) ) { $ keys = array_keys ( $ definition ) ; return array_reduce ( $ keys , function ( $ rules , $ key ) use ( $ definition ) { $ definition = $ definition [ $ key ] ; $ rule = $ this -> parseRuleDefinition ( $ key , $ definition ) ; return $ rules -> withRule ( $ rule ) ; } , new RulesCollection ) ; } throw new InvalidRuleFormatException ( $ definition ) ; }
Return a rules collection from a rule definition. It can be either a
callable, an array of callables, an array of factory names or a string of
rule factory names.

@param mixed $definition
@return \Ellipse\Validation\RulesCollection
Return a rules collection from a rule definition . It can be either a callable an array of callables an array of factory names or a string of rule factory names .