-
Notifications
You must be signed in to change notification settings - Fork 2
TypeConverterFactory
Warning
These docs are outdated and are no longer maintained. The manual is now on pg-wrapper.readthedocs.io
Classes that create type converters implement this interface.
It defines the following methods:
-
getConverterForTypeSpecification(mixed $type): TypeConverter- Returns a converter specified by a given type -
getConverterForTypeOID(int $oid): TypeConverter- Returns a converter for the type with the given OID -
getConverterForPHPValue(mixed $value): TypeConverter- Tries to return a converter based on type of$value -
setConnection(Connection $connection): $this- sets database connection info, to be able to load metadata for a particular database
getConverterForTypeSpecification() is used to get a converter for a user-supplied type (e.g. parameter types for executeParams()),
type specification is implementation dependent, arguments accepted by DefaultTypeConverterFactory are described on its page.
getConverterForTypeOID() is used to get converters for query result fields by ResultSet. It passes an OID (PostgreSQL's internal object identifier)
for a type as returned by pg_field_type_oid function.
Note that we don't use textual type description returned by pg_field_type
for the following reasons:
- Schema information is missing;
- Internally
pg_field_typejust loads the wholepg_catalog.pg_typedata into memory on the first call and later searches it for typeoid. We do the same inDefaultTypeConverterFactory, but load more info and allow caching of the resultant array.
The package contains two implementations of TypeConverterFactory: converters\DefaultTypeConverterFactory and
converters\StubTypeConverterFactory. getConverterForTypeSpecification() method of the latter will return
-
$type, if it is an instance ofTypeConverter. It will be configured with currentConnectionif it implementsConnectionAware. - An instance of
converters\StubConverterif$typeis anything else.
Its getConverterForTypeOID() and getConverterForPHPValue() also return StubConverter.
This can be used to essentially disable type conversion, making package behave like stock pgsql extension.