form/FormParser.php
/**
     * Parse form values.
     * @param array of FormField $form_fields or FormField if only one form field.
     * @param object $class.
     * @throws FormException
     */
Parse form values.
@param array of FormField $form_fields or FormField if only one form field.
@param object $class.
Parse form values . @param array of FormField $form_fields or FormField if only one form field . @param object $class .
public function parse($form_fields, $class) {
        if (! is_object($class)) {
            throw new \UnexpectedValueException("Invalid parameter class");
        }
        if (empty($form_fields)) {
            throw new \UnexpectedValueException("Invalid parameter form_fields");
        }
        if (! is_array($form_fields)) {
            $form_fields = array($form_fields);
        }
        foreach ($form_fields as $field) {
            if (! $field instanceof FormField) {
                throw new \UnexpectedValueException("Invalid parameter form_fields");
            }
        }
        if (! is_object($this->_http_method_helper)) {
            $this->_http_method_helper = new HttpMethodHelper();
        }
        $this->_invalid_fields = array();
        foreach ($form_fields as $field) {
            $this->parseField($field);
            if ($field->isInvalid() && ! $this->_is_check_all_fields) {
                break;
            }
        }
        $class = $this->dumpFormValue($form_fields, $class);
        if (! empty($this->_invalid_fields)) {
            throw new FormException($this->_invalid_fields[0]->getErrorMessage());
        }
    }
public function parse ( $ form_fields , $ class ) { if ( ! is_object ( $ class ) ) { throw new \ UnexpectedValueException ( " Invalid parameter class " ) ; } if ( empty ( $ form_fields ) ) { throw new \ UnexpectedValueException ( " Invalid parameter form_fields " ) ; } if ( ! is_array ( $ form_fields ) ) { $ form_fields = array ( $ form_fields ) ; } foreach ( $ form_fields as $ field ) { if ( ! $ field instanceof FormField ) { throw new \ UnexpectedValueException ( " Invalid parameter form_fields " ) ; } } if ( ! is_object ( $ this -> _http_method_helper ) ) { $ this -> _http_method_helper = new HttpMethodHelper ( ) ; } $ this -> _invalid_fields = array ( ) ; foreach ( $ form_fields as $ field ) { $ this -> parseField ( $ field ) ; if ( $ field -> isInvalid ( ) && ! $ this -> _is_check_all_fields ) { break ; } } $ class = $ this -> dumpFormValue ( $ form_fields , $ class ) ; if ( ! empty ( $ this -> _invalid_fields ) ) { throw new FormException ( $ this -> _invalid_fields [ 0 ] -> getErrorMessage ( ) ) ; } }
Parse form values.
Parse form values .