src/Koldy/Validator.php
public function getData(bool $trimStrings = null): array
    {
        $trimStrings = ($trimStrings === null) ? true : $trimStrings;
        $data = $this->data;

        foreach ($data as $key => $value) {
            if (array_key_exists($key, $this->rules)) {
                if ($value === '') {
                    // convert empty strings into nulls
                    $data[$key] = null;
                }
            }

            if ($trimStrings && is_string($data[$key])) {
                $data[$key] = trim($data[$key]);
            }
        }

        $csrfParameterName = Csrf::getParameterName();

        foreach ($this->rules as $field => $rules) {
            if ($field != $csrfParameterName && !array_key_exists($field, $data)) {
                $data[$field] = null;
            }

            if (isset($data[$field]) && is_string($data[$field]) && $rules !== null) {
	            $rules = explode('|', is_object($rules) && method_exists($rules, '__toString') ? $rules->__toString() : $rules);

                // case booleans
                if (in_array('bool', $rules) || in_array('boolean', $rules)) {
                    if ($data[$field] === 'true') {
                        $data[$field] = true;
                    } else if ($data[$field] === 'false') {
                        $data[$field] = false;
                    } else {
                        $data[$field] = (bool)$data[$field];
                    }
                } else if (in_array('integer', $rules)) {
                    $data[$field] = (int)$data[$field];
                }
            }
        }

        if ($this->isCsrfEnabled() && isset($data[$csrfParameterName])) {
            unset($data[$csrfParameterName]);
        }

        return $data;
    }
public function getData(bool $trimStrings = null): array
    {
        $trimStrings = ($trimStrings === null) ? true : $trimStrings;
        $data = $this->data;

        foreach ($data as $key => $value) {
            if (array_key_exists($key, $this->rules)) {
                if ($value === '') {
                    // convert empty strings into nulls
                    $data[$key] = null;
                }
            }

            if ($trimStrings && is_string($data[$key])) {
                $data[$key] = trim($data[$key]);
            }
        }

        $csrfParameterName = Csrf::getParameterName();

        foreach ($this->rules as $field => $rules) {
            if ($field != $csrfParameterName && !array_key_exists($field, $data)) {
                $data[$field] = null;
            }

            if (isset($data[$field]) && is_string($data[$field]) && $rules !== null) {
	            $rules = explode('|', is_object($rules) && method_exists($rules, '__toString') ? $rules->__toString() : $rules);

                // case booleans
                if (in_array('bool', $rules) || in_array('boolean', $rules)) {
                    if ($data[$field] === 'true') {
                        $data[$field] = true;
                    } else if ($data[$field] === 'false') {
                        $data[$field] = false;
                    } else {
                        $data[$field] = (bool)$data[$field];
                    }
                } else if (in_array('integer', $rules)) {
                    $data[$field] = (int)$data[$field];
                }
            }
        }

        if ($this->isCsrfEnabled() && isset($data[$csrfParameterName])) {
            unset($data[$csrfParameterName]);
        }

        return $data;
    }
public function getData ( bool $ trimStrings = null ) : array { $ trimStrings = ( $ trimStrings === null ) ? true : $ trimStrings ; $ data = $ this -> data ; foreach ( $ data as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> rules ) ) { if ( $ value === '' ) { // convert empty strings into nulls $ data [ $ key ] = null ; } } if ( $ trimStrings && is_string ( $ data [ $ key ] ) ) { $ data [ $ key ] = trim ( $ data [ $ key ] ) ; } } $ csrfParameterName = Csrf :: getParameterName ( ) ; foreach ( $ this -> rules as $ field => $ rules ) { if ( $ field != $ csrfParameterName && ! array_key_exists ( $ field , $ data ) ) { $ data [ $ field ] = null ; } if ( isset ( $ data [ $ field ] ) && is_string ( $ data [ $ field ] ) && $ rules !== null ) { $ rules = explode ( '|' , is_object ( $ rules ) && method_exists ( $ rules , '__toString' ) ? $ rules -> __toString ( ) : $ rules ) ; // case booleans if ( in_array ( 'bool' , $ rules ) || in_array ( 'boolean' , $ rules ) ) { if ( $ data [ $ field ] === 'true' ) { $ data [ $ field ] = true ; } else if ( $ data [ $ field ] === 'false' ) { $ data [ $ field ] = false ; } else { $ data [ $ field ] = ( bool ) $ data [ $ field ] ; } } else if ( in_array ( 'integer' , $ rules ) ) { $ data [ $ field ] = ( int ) $ data [ $ field ] ; } } } if ( $ this -> isCsrfEnabled ( ) && isset ( $ data [ $ csrfParameterName ] ) ) { unset ( $ data [ $ csrfParameterName ] ) ; } return $ data ; }
Get the data we're going to validate

@param bool $trimStrings

@return array
@throws Config\Exception
@throws Exception
Get the data we re going to validate