Skip to content

Latest commit

 

History

History
112 lines (86 loc) · 3.36 KB

File metadata and controls

112 lines (86 loc) · 3.36 KB

Symfony

Before integrating this library into a Symfony project, read the general installation instructions and install the library via Composer.

Setup

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 ]

Database Types

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: false

Note: The PostgreSQL native geometry and geography types are automatically mapped to Doctrine types during schema introspection. You don't need to add them to the mapping_types section.

DQL Functions

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 functions

Known Problems

PostGIS Schema Exclusion

Since 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.

Unknown Database Types

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: string

Note: 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.