src/Validator/Chain.php
private function parseChain($chain = []): void
    {
        if (!\is_array($chain)) {
            throw new InvalidArgumentException('Validators chain must be an array');
        }
        foreach ($chain as $k => $v) {
            if ($v instanceof AbstractSpecific) {
                // value is an instance of AbstractSpecific
                $reflection = new \ReflectionClass($v);
                $name = \str_replace($reflection->getNamespaceName().'\\', '', $reflection->getName());
                $this->chain[$name] = $v;
            } elseif (\is_string($k) && \is_array($v)) {
                // key is a string (validator name) and value is an array (validator options)
                $className = '\\MS\\LightFramework\\Validator\\Specific\\'.$k;
                if (!\class_exists($className)) {
                    throw new InvalidArgumentException('Validator "'.$k.'" not found');
                }
                $this->chain[$k] = new $className($v);
            } elseif (\is_numeric($k) && \is_array($v)) {
                // key is a numeric and value is an array (validator name => validator options)
                $this->parseChain($v);
            } else {
                // incorrect chain format
                $exMsg = 'Validator chain element must be either instance of AbstractValidator ';
                $exMsg .= 'or array("validatorName" => array(options))';
                throw new InvalidArgumentException($exMsg);
            }
        }
    }
private function parseChain($chain = []): void
    {
        if (!\is_array($chain)) {
            throw new InvalidArgumentException('Validators chain must be an array');
        }
        foreach ($chain as $k => $v) {
            if ($v instanceof AbstractSpecific) {
                // value is an instance of AbstractSpecific
                $reflection = new \ReflectionClass($v);
                $name = \str_replace($reflection->getNamespaceName().'\\', '', $reflection->getName());
                $this->chain[$name] = $v;
            } elseif (\is_string($k) && \is_array($v)) {
                // key is a string (validator name) and value is an array (validator options)
                $className = '\\MS\\LightFramework\\Validator\\Specific\\'.$k;
                if (!\class_exists($className)) {
                    throw new InvalidArgumentException('Validator "'.$k.'" not found');
                }
                $this->chain[$k] = new $className($v);
            } elseif (\is_numeric($k) && \is_array($v)) {
                // key is a numeric and value is an array (validator name => validator options)
                $this->parseChain($v);
            } else {
                // incorrect chain format
                $exMsg = 'Validator chain element must be either instance of AbstractValidator ';
                $exMsg .= 'or array("validatorName" => array(options))';
                throw new InvalidArgumentException($exMsg);
            }
        }
    }
private function parseChain ( $ chain = [ ] ) : void { if ( ! \ is_array ( $ chain ) ) { throw new InvalidArgumentException ( 'Validators chain must be an array' ) ; } foreach ( $ chain as $ k => $ v ) { if ( $ v instanceof AbstractSpecific ) { // value is an instance of AbstractSpecific $ reflection = new \ ReflectionClass ( $ v ) ; $ name = \ str_replace ( $ reflection -> getNamespaceName ( ) . '\\' , '' , $ reflection -> getName ( ) ) ; $ this -> chain [ $ name ] = $ v ; } elseif ( \ is_string ( $ k ) && \ is_array ( $ v ) ) { // key is a string (validator name) and value is an array (validator options) $ className = '\\MS\\LightFramework\\Validator\\Specific\\' . $ k ; if ( ! \ class_exists ( $ className ) ) { throw new InvalidArgumentException ( 'Validator "' . $ k . '" not found' ) ; } $ this -> chain [ $ k ] = new $ className ( $ v ) ; } elseif ( \ is_numeric ( $ k ) && \ is_array ( $ v ) ) { // key is a numeric and value is an array (validator name => validator options) $ this -> parseChain ( $ v ) ; } else { // incorrect chain format $ exMsg = 'Validator chain element must be either instance of AbstractValidator ' ; $ exMsg .= 'or array("validatorName" => array(options))' ; throw new InvalidArgumentException ( $ exMsg ) ; } } }
Parses chain array

@param array $chain
Parses chain array