Skip to content

Updated to doctrine 3 and dbal 4 #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ extension for [PostgreSQL](https://www.postgresql.org/).

* [Supported Versions](#supported-versions)
* [Installation](#installation)
* [Setup](#setup)
* [Symfony](#symfony)
* [Symfony Setup](#symfony-setup)
* [Property Mapping](#property-mapping)
* [Spatial Indexes](#spatial-indexes)
* [Schema Tool](#schema-tool)
Expand All @@ -25,12 +24,12 @@ Supported Versions
The following table shows the versions which are officially supported by this
library.

| Dependency | Supported Versions |
|:--------------|:--------------------|
| PostGIS | 3.0 and 3.1 |
| PostgreSQL | 11, 12 and 13 |
| Doctrine ORM | ^2.9 |
| Doctrine DBAL | ^2.13 and ^3.1 |
| Dependency | Supported Versions |
|:--------------|:-------------------|
| PostGIS | 3.0 and 3.1 |
| PostgreSQL | < 15 |
| Doctrine ORM | ^3.0.0 |
| Doctrine DBAL | ^4.1.1 |

Installation
--
Expand All @@ -44,30 +43,29 @@ composer require jsor/doctrine-postgis
Check the [Packagist page](https://packagist.org/packages/jsor/doctrine-postgis)
for all available versions.

Setup
Symfony Setup
--

To use the library with the Doctrine ORM, register the
`ORMSchemaEventSubscriber` event subscriber.
**Manual Bundle Registration**

```php
use Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber;
If Symfony Flex does not automatically register the bundle, you can manually add it to your ``config/bundles.php`` file:

$entityManager->getEventManager()->addEventSubscriber(new ORMSchemaEventSubscriber());
```php
return [
// Other bundles...
Jsor\Doctrine\PostGIS\JsorDoctrinePostgisBundle::class => ['all' => true],
];
```

To use it with the DBAL only, register the `DBALSchemaEventSubscriber` event
subscriber.
For integrating this library into a Symfony project, configure the schema manager factory in your ``doctrine.yaml``:

```php
use Jsor\Doctrine\PostGIS\Event\DBALSchemaEventSubscriber;

$connection->getEventManager()->addEventSubscriber(new DBALSchemaEventSubscriber());
# config/packages/doctrine.yaml
doctrine:
dbal:
schema_manager_factory: Jsor\Doctrine\PostGIS\Schema\PostGISSchemaManagerFactory
# rest of your configuration...
```
### Symfony

For integrating this library into a Symfony project, read the dedicated
[Symfony Documentation](docs/symfony.md).

Property Mapping
--
Expand Down Expand Up @@ -95,10 +93,10 @@ class MyEntity
There are 2 options to configure the geometry.

* `geometry_type`
This defines the type of the geometry, like `POINT`, `LINESTRING` etc.
If you omit this option, the generic type `GEOMETRY` is used.
This defines the type of the geometry, like `POINT`, `LINESTRING` etc.
If you omit this option, the generic type `GEOMETRY` is used.
* `srid`
This defines the Spatial Reference System Identifier (SRID) of the geometry.
This defines the Spatial Reference System Identifier (SRID) of the geometry.

### Example

Expand Down Expand Up @@ -177,15 +175,18 @@ class MyEntity
Schema Tool
--

Full support for the [ORM Schema Tool](https://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html)
and the [DBAL Schema Manager](https://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html)
Full support for
the [ORM Schema Tool](https://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/tools.html)
and
the [DBAL Schema Manager](https://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html)
is provided.

DQL Functions
--

Most [PostGIS functions](https://postgis.net/docs/reference.html) are also
available for the [Doctrine Query Language](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html)
available for
the [Doctrine Query Language](https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html)
(DQL) under the `Jsor\Doctrine\PostGIS\Functions` namespace.

For a full list of all supported functions, see the
Expand All @@ -195,7 +196,7 @@ For a full list of all supported functions, see the
> how to configure the functions with Symfony.

The functions must be registered with the `Doctrine\ORM\Configuration` instance.

```php
$configuration = new Doctrine\ORM\Configuration();

Expand Down Expand Up @@ -313,7 +314,7 @@ PHP container connected to specific database containers.
The script names follow the pattern
`run-<POSTGRESQL_VERSION>-<POSTGIS_VERSION>.sh`.

To run the test suite against PostgreSQL 13 with PostGIS 3.1, use the script
To run the test suite against PostgreSQL 13 with PostGIS 3.1, use the script
`./docker/run-13-31.sh`.

```bash
Expand Down
17 changes: 14 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "jsor/doctrine-postgis",
"type": "symfony-bundle",
"description": "Spatial and Geographic Data with PostGIS and Doctrine.",
"keywords": [
"spatial",
Expand All @@ -23,15 +24,20 @@
],
"require": {
"php": "^8.0",
"doctrine/dbal": "^2.13 || ^3.1"
"doctrine/dbal": "^4.1.1",
"symfony/framework-bundle": "^7.2",
"symfony/runtime": "^7.2"
},
"require-dev": {
"doctrine/orm": "^2.9",
"doctrine/orm": "^3.0.0",
"friendsofphp/php-cs-fixer": "^3.13",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^5.9",
"symfony/doctrine-bridge": "^5.4 || ^6.0",
"symfony/doctrine-messenger": "^5.4 || ^6.0"
"symfony/doctrine-messenger": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0"
},
"suggest": {
"doctrine/orm": "For using with the Doctrine ORM"
Expand All @@ -50,5 +56,10 @@
"branch-alias": {
"dev-main": "2.x-dev"
}
},
"config": {
"allow-plugins": {
"symfony/runtime": true
}
}
}
25 changes: 0 additions & 25 deletions docs/symfony.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,8 @@ Before integrating this library into a Symfony project, read the general
[installation instructions](../README.md#installation) and install the library
via Composer.

* [Setup](#setup)
* [Known Problems](#known-problems)

Setup
--

To use the library with the Doctrine ORM (version 2.9 or higher is supported),
register a [Doctrine event subscriber](https://symfony.com/doc/current/doctrine/event_listeners_subscribers.html)
in `config/services.yml`.

```yaml
services:
Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber:
tags:
- { name: doctrine.event_subscriber, connection: default }
```

The library can also be used with DBAL only (versions 2.13 or higher and 3.1 or
higher are supported).

```yaml
services:
Jsor\Doctrine\PostGIS\Event\DBALSchemaEventSubscriber:
tags:
- { name: doctrine.event_subscriber, connection: default }
```

### Database Types

Register the DBAL types in the
Expand Down
40 changes: 40 additions & 0 deletions src/DependencyInjection/DoctrineSchemaManagerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Jsor\Doctrine\PostGIS\DependencyInjection;

use Jsor\Doctrine\PostGIS\Schema\PostGISSchemaManagerFactory;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class DoctrineSchemaManagerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$container->register('app.postgis_schema_manager_factory', PostGISSchemaManagerFactory::class)
->setPublic(true)
;

foreach ($container->findTaggedServiceIds('doctrine.dbal.connection') as $id => $tags) {
$connectionDef = $container->getDefinition($id);
$params = $connectionDef->getArgument(0);

if (is_array($params)) {
$params['schema_manager_factory'] = new Reference('app.postgis_schema_manager_factory');
$connectionDef->replaceArgument(0, $params);
}
}

$doctrinePrefix = 'doctrine.dbal.default_connection.';

if ($container->hasParameter($doctrinePrefix . 'configuration')) {
$config = $container->getParameter($doctrinePrefix . 'configuration');

if (is_array($config)) {
$config['schema_manager_factory'] = 'app.postgis_schema_manager_factory';

$container->setParameter($doctrinePrefix . 'configuration', $config);
}
}
}
}
Loading