src/Bond/Pg/Result.php
private function buildFetchCallback( $fetchOptions, $flatten )
    {

        $original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
        $new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );

        // nothing has changed - don't need to change the callback
        if( $original === $new ) {
            return false;
        }

        // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)
        $this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM;

        // types and keys
        // determine types - this could be enabled to automatically convert types (to something other than a string)
        // off by default as the performance hit has yet to be determined
        if( $fetchOptions & self::TYPE_DETECT ) {

            $typeCallbacks = $this->getFieldTypeCallbacks();
            if( $this->fetchType === PGSQL_ASSOC ) {
                $keys = array_keys( $typeCallbacks );
            } else {
                $keys = range(0, count($typeCallbacks) - 1);
            }

            // flatten
            if( $flatten ) {

                $typeCallback = array_pop( $typeCallbacks );
                $this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) {
                    return call_user_func( $typeCallback, $row[0] );
                };

            } else {

                $this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) {
                    return array_combine(
                        $keys,
                        array_map( 'call_user_func', $typeCallbacks, $row )
                    );
                };

            }

        } elseif( $flatten ) {

            $this->fetchCallback = function( $row ) {
                return array_shift( $row );
            };

        } else {

            $this->fetchCallback = function( $row ) {
                return $row;
            };

        }

        return true;

    }
private function buildFetchCallback( $fetchOptions, $flatten )
    {

        $original = $this->fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );
        $new = $fetchOptions & ( self::TYPE_DETECT | self::TYPE_AGNOSTIC | self::FLATTEN_IF_POSSIBLE | self::FLATTEN_PREVENT | self::STYLE_ASSOC | self::STYLE_NUM );

        // nothing has changed - don't need to change the callback
        if( $original === $new ) {
            return false;
        }

        // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway)
        $this->fetchType = ( $fetchOptions & self::STYLE_ASSOC and !$flatten ) ? PGSQL_ASSOC : PGSQL_NUM;

        // types and keys
        // determine types - this could be enabled to automatically convert types (to something other than a string)
        // off by default as the performance hit has yet to be determined
        if( $fetchOptions & self::TYPE_DETECT ) {

            $typeCallbacks = $this->getFieldTypeCallbacks();
            if( $this->fetchType === PGSQL_ASSOC ) {
                $keys = array_keys( $typeCallbacks );
            } else {
                $keys = range(0, count($typeCallbacks) - 1);
            }

            // flatten
            if( $flatten ) {

                $typeCallback = array_pop( $typeCallbacks );
                $this->fetchCallback = function( $row ) use ( $keys, $typeCallback ) {
                    return call_user_func( $typeCallback, $row[0] );
                };

            } else {

                $this->fetchCallback = function( $row ) use ( $keys, $typeCallbacks ) {
                    return array_combine(
                        $keys,
                        array_map( 'call_user_func', $typeCallbacks, $row )
                    );
                };

            }

        } elseif( $flatten ) {

            $this->fetchCallback = function( $row ) {
                return array_shift( $row );
            };

        } else {

            $this->fetchCallback = function( $row ) {
                return $row;
            };

        }

        return true;

    }
private function buildFetchCallback ( $ fetchOptions , $ flatten ) { $ original = $ this -> fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC | self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT | self :: STYLE_ASSOC | self :: STYLE_NUM ) ; $ new = $ fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC | self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT | self :: STYLE_ASSOC | self :: STYLE_NUM ) ; // nothing has changed - don't need to change the callback if ( $ original === $ new ) { return false ; } // only fetch assoc if we're configured for it and we aren't flattening (which would destroy it anyway) $ this -> fetchType = ( $ fetchOptions & self :: STYLE_ASSOC and ! $ flatten ) ? PGSQL_ASSOC : PGSQL_NUM ; // types and keys // determine types - this could be enabled to automatically convert types (to something other than a string) // off by default as the performance hit has yet to be determined if ( $ fetchOptions & self :: TYPE_DETECT ) { $ typeCallbacks = $ this -> getFieldTypeCallbacks ( ) ; if ( $ this -> fetchType === PGSQL_ASSOC ) { $ keys = array_keys ( $ typeCallbacks ) ; } else { $ keys = range ( 0 , count ( $ typeCallbacks ) - 1 ) ; } // flatten if ( $ flatten ) { $ typeCallback = array_pop ( $ typeCallbacks ) ; $ this -> fetchCallback = function ( $ row ) use ( $ keys , $ typeCallback ) { return call_user_func ( $ typeCallback , $ row [ 0 ] ) ; } ; } else { $ this -> fetchCallback = function ( $ row ) use ( $ keys , $ typeCallbacks ) { return array_combine ( $ keys , array_map ( 'call_user_func' , $ typeCallbacks , $ row ) ) ; } ; } } elseif ( $ flatten ) { $ this -> fetchCallback = function ( $ row ) { return array_shift ( $ row ) ; } ; } else { $ this -> fetchCallback = function ( $ row ) { return $ row ; } ; } return true ; }
Build a row processing callback based on the TYPE_DETECT and row flattening
@param bool $flatten
@return Callable
Build a row processing callback based on the TYPE_DETECT and row flattening