public function isValid()
    {
        $this->errors = array();

        foreach ($this->rules() as $rule) {
            $fields = array_map('trim', explode(',', $rule[0]));
            $ruleName = $rule[1];
            $params = array_slice($rule, 2);

            // check scenario
            if (!empty($rule['on'])) {
                $onScenarios = explode(',', $rule['on']);
                if (!in_array($this->getScenario(), $onScenarios)) {
                    continue;
                }
            }

            if (!empty($rule['except'])) {
                $exceptScenarios = explode(',', $rule['except']);
                if (in_array($this->getScenario(), $exceptScenarios)) {
                    continue;
                }
            }

            if (method_exists($this, $ruleName)) {
                // method
                foreach ($fields as $field) {
                    $this->{$ruleName}($field, $params);
                }
            } else {
                // validator class
                $validatorClassName = $this->getValidatorClassNameByRuleName($ruleName);

                /* @var $validator \Sokil\Mongo\Validator */
                $validator = new $validatorClassName;
                if (!$validator instanceof Validator) {
                    throw new Exception('Validator class must implement \Sokil\Mongo\Validator class');
                }

                $validator->validate($this, $fields, $params);
            }
        }

        return !$this->hasErrors();
    }
public function isValid()
    {
        $this->errors = array();

        foreach ($this->rules() as $rule) {
            $fields = array_map('trim', explode(',', $rule[0]));
            $ruleName = $rule[1];
            $params = array_slice($rule, 2);

            // check scenario
            if (!empty($rule['on'])) {
                $onScenarios = explode(',', $rule['on']);
                if (!in_array($this->getScenario(), $onScenarios)) {
                    continue;
                }
            }

            if (!empty($rule['except'])) {
                $exceptScenarios = explode(',', $rule['except']);
                if (in_array($this->getScenario(), $exceptScenarios)) {
                    continue;
                }
            }

            if (method_exists($this, $ruleName)) {
                // method
                foreach ($fields as $field) {
                    $this->{$ruleName}($field, $params);
                }
            } else {
                // validator class
                $validatorClassName = $this->getValidatorClassNameByRuleName($ruleName);

                /* @var $validator \Sokil\Mongo\Validator */
                $validator = new $validatorClassName;
                if (!$validator instanceof Validator) {
                    throw new Exception('Validator class must implement \Sokil\Mongo\Validator class');
                }

                $validator->validate($this, $fields, $params);
            }
        }

        return !$this->hasErrors();
    }
public function isValid ( ) { $ this -> errors = array ( ) ; foreach ( $ this -> rules ( ) as $ rule ) { $ fields = array_map ( 'trim' , explode ( ',' , $ rule [ 0 ] ) ) ; $ ruleName = $ rule [ 1 ] ; $ params = array_slice ( $ rule , 2 ) ; // check scenario if ( ! empty ( $ rule [ 'on' ] ) ) { $ onScenarios = explode ( ',' , $ rule [ 'on' ] ) ; if ( ! in_array ( $ this -> getScenario ( ) , $ onScenarios ) ) { continue ; } } if ( ! empty ( $ rule [ 'except' ] ) ) { $ exceptScenarios = explode ( ',' , $ rule [ 'except' ] ) ; if ( in_array ( $ this -> getScenario ( ) , $ exceptScenarios ) ) { continue ; } } if ( method_exists ( $ this , $ ruleName ) ) { // method foreach ( $ fields as $ field ) { $ this -> { $ ruleName } ( $ field , $ params ) ; } } else { // validator class $ validatorClassName = $ this -> getValidatorClassNameByRuleName ( $ ruleName ) ; /* @var $validator \Sokil\Mongo\Validator */ $ validator = new $ validatorClassName ; if ( ! $ validator instanceof Validator ) { throw new Exception ( 'Validator class must implement \Sokil\Mongo\Validator class' ) ; } $ validator -> validate ( $ this , $ fields , $ params ) ; } } return ! $ this -> hasErrors ( ) ; }
Check if filled model params is valid

@return boolean

@throws Exception
Check if filled model params is valid