public static function makeFromShorthand(array $data = array(), array $fields = array()) {
        /** @type \Titon\Utility\Validator $obj */
        $obj = new static($data);

        foreach ($fields as $field => $data) {
            $title = $field;

            // Convert to array
            if (is_string($data)) {
                $data = array('rules' => $data);

            } else if (!is_array($data)) {
                continue;

            } else if (Hash::isNumeric(array_keys($data))) {
                $data = array('rules' => $data);
            }

            // Prepare for parsing
            if (isset($data['title'])) {
                $title = $data['title'];
            }

            if (is_string($data['rules'])) {
                $data['rules'] = explode('|', $data['rules']);
            }

            $obj->addField($field, $title);

            foreach ($data['rules'] as $ruleOpts) {
                $shorthand = self::splitShorthand($ruleOpts);

                $obj->addRule($field, $shorthand['rule'], $shorthand['message'], $shorthand['options']);
            }
        }

        return $obj;
    }
public static function makeFromShorthand(array $data = array(), array $fields = array()) {
        /** @type \Titon\Utility\Validator $obj */
        $obj = new static($data);

        foreach ($fields as $field => $data) {
            $title = $field;

            // Convert to array
            if (is_string($data)) {
                $data = array('rules' => $data);

            } else if (!is_array($data)) {
                continue;

            } else if (Hash::isNumeric(array_keys($data))) {
                $data = array('rules' => $data);
            }

            // Prepare for parsing
            if (isset($data['title'])) {
                $title = $data['title'];
            }

            if (is_string($data['rules'])) {
                $data['rules'] = explode('|', $data['rules']);
            }

            $obj->addField($field, $title);

            foreach ($data['rules'] as $ruleOpts) {
                $shorthand = self::splitShorthand($ruleOpts);

                $obj->addRule($field, $shorthand['rule'], $shorthand['message'], $shorthand['options']);
            }
        }

        return $obj;
    }
public static function makeFromShorthand ( array $ data = array ( ) , array $ fields = array ( ) ) { /** @type \Titon\Utility\Validator $obj */ $ obj = new static ( $ data ) ; foreach ( $ fields as $ field => $ data ) { $ title = $ field ; // Convert to array if ( is_string ( $ data ) ) { $ data = array ( 'rules' => $ data ) ; } else if ( ! is_array ( $ data ) ) { continue ; } else if ( Hash :: isNumeric ( array_keys ( $ data ) ) ) { $ data = array ( 'rules' => $ data ) ; } // Prepare for parsing if ( isset ( $ data [ 'title' ] ) ) { $ title = $ data [ 'title' ] ; } if ( is_string ( $ data [ 'rules' ] ) ) { $ data [ 'rules' ] = explode ( '|' , $ data [ 'rules' ] ) ; } $ obj -> addField ( $ field , $ title ) ; foreach ( $ data [ 'rules' ] as $ ruleOpts ) { $ shorthand = self :: splitShorthand ( $ ruleOpts ) ; $ obj -> addRule ( $ field , $ shorthand [ 'rule' ] , $ shorthand [ 'message' ] , $ shorthand [ 'options' ] ) ; } } return $ obj ; }
Create a validator instance from a set of shorthand or expanded rule sets.

@param array $data
@param array $fields
@return $this
Create a validator instance from a set of shorthand or expanded rule sets .