src/Validator/Validator.php
public function valid($value)
    {

        foreach($this->getRules() as $index => $rule) {

            // check for required
            if (in_array($value, ['', null]) && !$this->hasRule('required')) {
                continue;
            }

            // extract params
            list($method, $params) = $rule;

            // If method is null, we use the index as the method name
            $method = is_null($method) ? $index : $method;

            // Build the params
            array_unshift($params, $value);

            // If it's a anonymous function
            if (!is_string($method) && is_callable($method)) {

                if (!call_user_func_array($method, $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }

            } else {// if it's a local method

                if (!method_exists($this, $method)) {
                    throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
                }

                if (!call_user_func_array([$this, $method], $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }
            }
        }

        return $this;
    }
public function valid($value)
    {

        foreach($this->getRules() as $index => $rule) {

            // check for required
            if (in_array($value, ['', null]) && !$this->hasRule('required')) {
                continue;
            }

            // extract params
            list($method, $params) = $rule;

            // If method is null, we use the index as the method name
            $method = is_null($method) ? $index : $method;

            // Build the params
            array_unshift($params, $value);

            // If it's a anonymous function
            if (!is_string($method) && is_callable($method)) {

                if (!call_user_func_array($method, $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }

            } else {// if it's a local method

                if (!method_exists($this, $method)) {
                    throw new \Exception('Method "'. $method .'" not found for validator : ' . $index);
                }

                if (!call_user_func_array([$this, $method], $params)) {
                    $this->addError($index, $this->formatError($index, $params));
                }
            }
        }

        return $this;
    }
public function valid ( $ value ) { foreach ( $ this -> getRules ( ) as $ index => $ rule ) { // check for required if ( in_array ( $ value , [ '' , null ] ) && ! $ this -> hasRule ( 'required' ) ) { continue ; } // extract params list ( $ method , $ params ) = $ rule ; // If method is null, we use the index as the method name $ method = is_null ( $ method ) ? $ index : $ method ; // Build the params array_unshift ( $ params , $ value ) ; // If it's a anonymous function if ( ! is_string ( $ method ) && is_callable ( $ method ) ) { if ( ! call_user_func_array ( $ method , $ params ) ) { $ this -> addError ( $ index , $ this -> formatError ( $ index , $ params ) ) ; } } else { // if it's a local method if ( ! method_exists ( $ this , $ method ) ) { throw new \ Exception ( 'Method "' . $ method . '" not found for validator : ' . $ index ) ; } if ( ! call_user_func_array ( [ $ this , $ method ] , $ params ) ) { $ this -> addError ( $ index , $ this -> formatError ( $ index , $ params ) ) ; } } } return $ this ; }
Valid the element

@param $value
@return $this
Valid the element