Return a instanceof TypeConversionInterface which can converts (named) postgres type to a php value of the correct type

@param string fieldType, see, http://www.postgresql.org/docs/8.4/static/datatype.html
@return Bond\Pg\TypeConversionInterface
354573
public static function get( $type, Result $result )
    {

        switch( true ) {

            case $type === 'bool':
                return new Bool('bool');

            case $type === 'oid':
            case $type === 'int4':
            case $type === 'int8':

            # exotic from here down
            case $type === 'int2':
            case $type === 'oidvector':
                return new NullSafeCallback( $type, 'intval');

            case substr( $type, 0, 4 ) === '_int':
                return new GenericArray( $type, true );

            case $type === 'citext':
            case $type === 'text':
            case $type === 'char':
            case $type === 'name':
            # exotic from here down
            case $type === 'int2vector':
            case $type === 'pg_node_tree': # seems to be stored internally as text so pass it off
                return new NullSafeCallback( $type, 'strval');

            case $type === 'bit':
            case $type === 'varbit':
                return new NullSafeCallback( $type, 'bindec');

            case $type === 'bytea':
                return new NullSafeCallback( $type, 'pg_unescape_bytea');

            case $type === 'oid':
                return new NullSafeObjectInstantiation( $type, '\\Bond\\Entity\\Types\\Oid', [$result->db] );

            case $type === 'timestamp':
                return new NullSafeObjectInstantiation( $type, "\\Bond\\Entity\\Types\\DateTime");

            case $type === 'json':
                return new NullSafeObjectInstantiation( $type, "\\Bond\\Entity\\Types\\Json", [Json::VALIDATE_DISABLE] );

            case $type === 'inet':
                return new NullSafeObjectInstantiation( $type, "\\Bond\\Entity\\Types\\Inet");

            case $type === 'hstore':
                return new NullSafeObjectInstantiation( $type, "\\Bond\\Entity\\Types\\Hstore");

            case $type === 'interval':
                return new NullSafeObjectInstantiation( $type, "\\Bond\\Entity\\Types\\DateInterval");

            case  $type === 'tsrange':
                return new DateRange( $type );

            case $type === 'StockState':
                return new StockState( $type );

            case $type[0] === '_':
                return new GenericArray( $type, false);

            // entity dataTypes
//            case Repository::isEntity( substr( $type, 1 ) ):
//
//                return new Repository( substr( $type, 1 ) );

            // some different strategies for handling unknown types
            default:

                print_r($type);

                return new NullSafeCallback( $type, 'strval');

                /*
                return new LegacyCallback( $type, function( $value ) use ( $type ) {
                    echo "{$type} - {$value}\n";
                    return new LegacyCallback( $type, (string) $type);
                });
                */

                throw new UnknownPostgresType( "`{$type}`: You might consider expanding this switch statement." );

        }

    }
466441
public function type($type)
    {
        $type = strtoupper($type);

        if (!in_array($type, ['INSERT', 'INSERT IGNORE', 'REPLACE'])) {
            throw new \UnexpectedValueException('Invalid insert type');
        }

        $this->type = $type;

        return $this;
    }
1149503
public function resolveType($value) {
        if ($value === null) {
            $type = PDO::PARAM_NULL;

        } else if (is_resource($value)) {
            $type = PDO::PARAM_LOB;

        } else if (is_numeric($value)) {
            if (is_float($value) || is_double($value)) {
                $type = PDO::PARAM_STR; // Uses string type

            } else {
                $type = PDO::PARAM_INT;
            }

        } else if (is_bool($value)) {
            $type = PDO::PARAM_BOOL;

        } else {
            $type = PDO::PARAM_STR;
        }

        return $type;
    }
464500
public static function dataTypeToEavColumn($type)
    {
        switch ($type) {
            case Property::DATA_TYPE_FLOAT:
                return 'value_float';
                break;

            case Property::DATA_TYPE_BOOLEAN:
            case Property::DATA_TYPE_INTEGER:
                return 'value_integer';
                break;

            case Property::DATA_TYPE_TEXT:
            case Property::DATA_TYPE_PACKED_JSON:
            case Property::DATA_TYPE_INVARIANT_STRING:
                return 'value_text';
                break;

            case Property::DATA_TYPE_STRING:
            default:
                return 'value_string';
                break;
        }
    }
370554
private function convert($type, $reverse = false)
    {
        $replace = array_merge(
            $this->getJpgReplace(),
            $this->getBmpReplace()
        );

        if ( $reverse ) {
            $replace = array_flip($replace);
        }

        return str_replace(array_keys($replace), array_values($replace), $type);
    }
141237
public function getFieldType($type)
    {
        $types = array_keys(static::$availableFieldTypes);

        if (!$type || trim($type) == '') {
            throw new \InvalidArgumentException('Field type must be provided.');
        }

        if (array_key_exists($type, $this->customTypes)) {
            return $this->customTypes[$type];
        }

        if (!in_array($type, $types)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Unsupported field type [%s]. Available types are: %s',
                    $type,
                    join(', ', array_merge($types, array_keys($this->customTypes)))
                )
            );
        }

        $namespace = __NAMESPACE__.'\\Fields\\';

        return $namespace . static::$availableFieldTypes[$type];
    }
313196
public function fieldType($result_object,$index,$which_connection='')
    {
        if ($which_connection == '') {
            $which_connection = $this->default_db;
        }
        $fld = $result_object->FetchField($index);
        // mysqli puts a integer constant in the type property
        // ADOdb provides MetaType to convert to relative type
        $dbtype = $this->connectionType($which_connection);
        if (strtolower($dbtype) === 'mysqli') {
            $meta = $this->connections[$which_connection]->MetaType($fld->type);
            switch ($meta) {
                case 'C':
                case 'X':
                    $fld->type = 'varchar';
                    break;
                case 'B':
                case 'X':
                    $fld->type= 'blob';
                    break;
                case 'D':
                case 'T':
                    $fld->type= 'datetime';
                    break;
                case 'R':
                case 'I':
                    $fld->type= 'int';
                    break;
                case 'N':
                    $fld->type= 'numeric';
                    break;
            }
        }

        return $fld->type;
    }
845754
private function getCommonType($field)
    {
        static $types = [
            // MYSQLI_TYPE_BIT => CommonTypes::T,
            MYSQLI_TYPE_BLOB => CommonTypes::TTEXT,
            // MYSQLI_TYPE_CHAR => CommonTypes::TINT, // MYSQLI_TYPE_TINY is the same as MYSQLI_TYPE_CHAR
            MYSQLI_TYPE_DATE => CommonTypes::TDATE,
            MYSQLI_TYPE_DATETIME => CommonTypes::TDATETIME,
            MYSQLI_TYPE_DECIMAL => CommonTypes::TNUMBER,
            MYSQLI_TYPE_DOUBLE => CommonTypes::TNUMBER,
            // MYSQLI_TYPE_ENUM => CommonTypes::T,
            MYSQLI_TYPE_FLOAT => CommonTypes::TNUMBER,
            // MYSQLI_TYPE_GEOMETRY => CommonTypes::T,
            MYSQLI_TYPE_INT24 => CommonTypes::TINT,
            // MYSQLI_TYPE_INTERVAL => CommonTypes::T,
            MYSQLI_TYPE_LONG => CommonTypes::TINT,
            MYSQLI_TYPE_LONGLONG => CommonTypes::TINT,
            MYSQLI_TYPE_LONG_BLOB => CommonTypes::TTEXT,
            MYSQLI_TYPE_MEDIUM_BLOB => CommonTypes::TTEXT,
            MYSQLI_TYPE_NEWDATE => CommonTypes::TDATE,
            MYSQLI_TYPE_NEWDECIMAL => CommonTypes::TNUMBER,
            // MYSQLI_TYPE_NULL => CommonTypes::T,
            // MYSQLI_TYPE_SET => CommonTypes::T,
            MYSQLI_TYPE_SHORT => CommonTypes::TINT,
            MYSQLI_TYPE_STRING => CommonTypes::TTEXT,
            MYSQLI_TYPE_TIME => CommonTypes::TTIME,
            MYSQLI_TYPE_TIMESTAMP => CommonTypes::TINT,
            MYSQLI_TYPE_TINY => CommonTypes::TINT,
            MYSQLI_TYPE_TINY_BLOB => CommonTypes::TTEXT,
            MYSQLI_TYPE_VAR_STRING => CommonTypes::TTEXT,
            MYSQLI_TYPE_YEAR => CommonTypes::TINT,
        ];
        if (isset($this->overrideTypes[$field->{'name'}])) {
            return $this->overrideTypes[$field->{'name'}];
        }
        $type = CommonTypes::TTEXT;
        if (array_key_exists($field->{'type'}, $types)) {
            $type = $types[$field->{'type'}];
            if (1 == $field->{'length'} && ($type == CommonTypes::TINT || $type == CommonTypes::TNUMBER)) {
                $type = CommonTypes::TBOOL;
            } elseif ($type == CommonTypes::TNUMBER && $field->{'decimals'} == 0) {
                $type = CommonTypes::TINT;
            }
        }
        return $type;
    }
226051
protected function mapFieldTypeToBindType($native_type)
    {
        $oracleDatatypeMap = array(
            'varchar2' => 'string',
            'nvarchar2' => 'string',
            'number' => 'number',
            'long' => 'number',
            'date' => 'datetime',
            'binary_float' => 'number',
            'binary_double' => 'number',
            'timestamp' => 'datetime',
            'interval year' => 'datetime',
            'interval day' => 'datetime',
            'raw' => 'string',
            'long raw' => 'string',
            'rowid' => 'string',
            'urowid' => 'string',
            'char' => 'string',
            'nchar' => 'string',
            'clob' => 'string',
            'nclob' => 'string',
            'blob' => 'string',
            'bfile' => 'string',
        );
        
        $native_type = strtolower($native_type);
        if (isset($oracleDatatypeMap[$native_type])) {
            return $oracleDatatypeMap[$native_type];
        } else {
            return "unknown";
        }
    }
1163341
public static function factory($type=0, $table = null, $fields = null)
    {       
        if ($type instanceof ObjectDefinition) {
            $type_id = $type->id;
            $od = $type;
        } elseif ((int)$type) {
            $type_id = (int)$type;
            $od = new ObjectDefinition($type_id, $table);
        }
            
        switch ($type_id) {
            case User::TYPE:
                $o = User::create();
                break;
            case Catalog::TYPE:
				if ($fields && $fields['is_server']) {
					$o  = Server::create();
					break;
				}
                $o = Catalog::create();
                break;
            default:
				if ( isset(ObjectDefinition::$userClasses[$type_id]) ) {
					$uc = ObjectDefinition::$userClasses[$type_id];
					$o = $uc::create();
				} else {
					$o = Material::create();
				}
                break;
        }
		
		$o->objectDefinition = $od;

        return $o;
    }
1280474
public function getPDOType($value) {
        $type= null;
        if (is_null($value)) $type= \PDO::PARAM_NULL;
        elseif (is_scalar($value)) {
            if (is_int($value)) $type= \PDO::PARAM_INT;
            else $type= \PDO::PARAM_STR;
        }
        return $type;
    }
792270
public function getFieldTypeCallbacks()
    {
        $types = array();

        $numFields = $this->numFields();
        for( $i = 0; $i < $numFields; $i++ ) {
            $types[pg_field_name( $this->resource, $i )] = TypeConversionFactory::get(
                pg_field_type( $this->resource, $i ),
                $this
            );
        }

        return $types;
    }
879446
public function getIdentifierPhp($columnValueMutator, $connectionVariableName = '$con', $sequenceName = '', $tab = "            ", $phpType = null)
    {
        if (!$sequenceName) {
            throw new EngineException('PostgreSQL needs a sequence name to fetch primary keys');
        }
        $snippet = "
\$dataFetcher = %s->query(\"SELECT nextval('%s')\");
%s = %s\$dataFetcher->fetchColumn();";
        $script = sprintf($snippet,
            $connectionVariableName,
            $sequenceName,
            $columnValueMutator,
            $phpType ? '('.$phpType.') ' : ''
        );

        return preg_replace('/^/m', $tab, $script);
    }
24426
function fieldconfigurer($fieldtype = null) {
		$fieldtype !== null or $fieldtype = 'field';
		if ($this->fieldconfigurers !== null) {
			if (isset($this->fieldconfigurers[$fieldtype])) {
				return $this->fieldconfigurers[$fieldtype];
			}
			else if (isset($this->fieldconfigurers['field'])) {
				return $this->fieldconfigurers['field'];
			}
		}

		return null; # no configurer
	}
410907
public function convert($field, $type, array $options = []) {
        if (!isset($this->_defaults[$type])) {
            throw new InvalidArgumentException(sprintf('Converter %s does not exist', $type));
        }

        $this->_converters[$field] = Hash::merge([
            'encode' => true,
            'decode' => true,
            'type' => $type,
        ], $this->_defaults[$type], $options);

        return $this;
    }
1045652
public function convertStringToPHPValue(AbstractSpatialType $type, $sqlExpr)
    {
        $parser = new StringParser($sqlExpr);

        return $this->newObjectFromValue($type, $parser->parse());
    }
1044178
function fieldtemplate($fieldtype = null) {
		$fieldtype !== null or $fieldtype = 'field';
		if ($this->fieldtemplates !== null) {
			if (isset($this->fieldtemplates[$fieldtype])) {
				return $this->fieldtemplates[$fieldtype];
			}
			else if (isset($this->fieldtemplates['field'])) {
				return $this->fieldtemplates['field'];
			}
		}

		// hard default: display field only
		return ':field';
	}