code/model/state/state.php
protected function _sanitize($state)
    {
        //Treat empty string as null
        if ($state->value === '') {
            $state->value = null;
        }

        //Only filter if we have a value
        if(!empty($state->value))
        {
            //Only accepts scalar values and array
            if(!is_scalar($state->value) && !is_array($state->value))
            {
                throw new \UnexpectedValueException(
                    'Value needs to be an array or a scalar, "'.gettype($state->value).'" given'
                );
            }

            $filter = $state->filter;

            if(!($filter instanceof FilterInterface)) {
                $filter =  $this->getObject('filter.factory')->createChain($filter);
            }

            $state->value = $filter->sanitize($state->value);
        }

        return $state;
    }
protected function _sanitize($state)
    {
        //Treat empty string as null
        if ($state->value === '') {
            $state->value = null;
        }

        //Only filter if we have a value
        if(!empty($state->value))
        {
            //Only accepts scalar values and array
            if(!is_scalar($state->value) && !is_array($state->value))
            {
                throw new \UnexpectedValueException(
                    'Value needs to be an array or a scalar, "'.gettype($state->value).'" given'
                );
            }

            $filter = $state->filter;

            if(!($filter instanceof FilterInterface)) {
                $filter =  $this->getObject('filter.factory')->createChain($filter);
            }

            $state->value = $filter->sanitize($state->value);
        }

        return $state;
    }
protected function _sanitize ( $ state ) { //Treat empty string as null if ( $ state -> value === '' ) { $ state -> value = null ; } //Only filter if we have a value if ( ! empty ( $ state -> value ) ) { //Only accepts scalar values and array if ( ! is_scalar ( $ state -> value ) && ! is_array ( $ state -> value ) ) { throw new \ UnexpectedValueException ( 'Value needs to be an array or a scalar, "' . gettype ( $ state -> value ) . '" given' ) ; } $ filter = $ state -> filter ; if ( ! ( $ filter instanceof FilterInterface ) ) { $ filter = $ this -> getObject ( 'filter.factory' ) -> createChain ( $ filter ) ; } $ state -> value = $ filter -> sanitize ( $ state -> value ) ; } return $ state ; }
Sanitize a state by filtering the state value

@param  object  $state The state object.
@throws \UnexpectedValueException If the value is not a scalar or an array
@return object
Sanitize a state by filtering the state value