Before integrating this library into a Symfony project, read the general installation instructions and install the library via Composer.
To use the library with the Doctrine ORM (version 2.9 or higher is supported),
register a Doctrine event subscriber
in config/packages/jsor_doctrine_postgis.yaml.
services:
Jsor\Doctrine\PostGIS\Event\ORMSchemaEventListener:
tags: [{ name: doctrine.event_listener, event: postGenerateSchemaTable, connection: default }]
Jsor\Doctrine\PostGIS\Driver\Middleware:
tags: [ doctrine.middleware ]Register the DBAL types in the
doctrine section
of the config/packages/doctrine.yaml config file.
doctrine:
dbal:
types:
geography:
class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
commented: false
geometry:
class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
commented: falseNote: The PostgreSQL native
geometryandgeographytypes are automatically mapped to Doctrine types during schema introspection. You don't need to add them to themapping_typessection.
To use the DQL functions provided by this library, they must be configured in
config/packages/doctrine.yaml.
doctrine:
orm:
dql:
string_functions:
ST_Within: Jsor\Doctrine\PostGIS\Functions\ST_Within
# ...other string functions
numeric_functions:
ST_Distance: Jsor\Doctrine\PostGIS\Functions\ST_Distance
# ...other numeric functionsSince PostGIS can add a few new schemas, like topology, tiger and
tiger_data, you might want to exclude them from being handled by Doctrine,
especially when you use the Doctrine Migrations Bundle.
This can be done by configuring the schema_filter option in
config/packages/doctrine.yaml.
doctrine:
dbal:
schema_filter: ~^(?!tiger)(?!topology)~See also Manual Tables in the Symfony documentation.
Sometimes, the schema tool stumbles upon database types it can't handle. A common exception is something like
Doctrine\DBAL\Exception: Unknown database type _text requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.
To solve this, the unknown database types can be mapped to known types with the
mapping_types option in config/packages/doctrine.yaml.
doctrine:
dbal:
mapping_types:
_text: stringNote: This type is then not suited to be used in entity mappings. It just prevents "Unknown database type..." exceptions thrown during database inspections by the schema tool.
If you want to use this type in your entities, you have to configure real database types, e.g. with the PostgreSQL for Doctrine package.