Skip to content

Commit 55436b6

Browse files
committed
feat(doctrine): add support to doctrine into symfony bundle
1 parent 8cbce14 commit 55436b6

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"require-dev": {
3232
"api-platform/core": "^3.0.4 || ^4",
3333
"doctrine/annotations": "^2.0",
34+
"doctrine/doctrine-bundle": "^2.15",
3435
"doctrine/collections": "^2.2",
3536
"doctrine/inflector": "^2.0",
3637
"doctrine/orm": "^3.3",

src/Symfony/Bundle/DependencyInjection/AutoMapperExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public function load(array $configs, ContainerBuilder $container): void
144144
$loader->load('api_platform.php');
145145
}
146146

147+
if ($config['doctrine']) {
148+
$loader->load('doctrine.php');
149+
}
150+
147151
if (null !== $config['name_converter']) {
148152
if ($container->has('automapper.mapping.metadata_aware_name_converter')) {
149153
$container->getDefinition('automapper.mapping.metadata_aware_name_converter')

src/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function getConfigTreeBuilder(): TreeBuilder
4343
->end()
4444
->booleanNode('serializer_attributes')->defaultValue(interface_exists(SerializerInterface::class))->end()
4545
->booleanNode('api_platform')->defaultFalse()->end()
46+
->booleanNode('doctrine')->defaultFalse()->end()
4647
->scalarNode('name_converter')->defaultNull()->end()
4748
->arrayNode('loader')
4849
->children()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
6+
7+
use AutoMapper\Event\GenerateMapperEvent;
8+
use AutoMapper\Event\PropertyMetadataEvent;
9+
use AutoMapper\EventListener\Doctrine\DoctrineIdentifierListener;
10+
use AutoMapper\EventListener\Doctrine\DoctrineProviderListener;
11+
use AutoMapper\Provider\Doctrine\DoctrineProvider;
12+
use Doctrine\ORM\EntityManagerInterface;
13+
14+
return static function (ContainerConfigurator $container) {
15+
$container->services()
16+
->set(DoctrineIdentifierListener::class)
17+
->args([service(EntityManagerInterface::class)])
18+
->tag('kernel.event_listener', ['event' => PropertyMetadataEvent::class, 'priority' => 0])
19+
20+
->set(DoctrineProviderListener::class)
21+
->args([service(EntityManagerInterface::class)])
22+
->tag('kernel.event_listener', ['event' => GenerateMapperEvent::class, 'priority' => 0])
23+
24+
->set(DoctrineProvider::class)
25+
->args([service(EntityManagerInterface::class)])
26+
->tag('automapper.provider', ['priority' => 0])
27+
;
28+
};

tests/Bundle/Resources/config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
Symfony\Bundle\TwigBundle\TwigBundle::class => ['dev' => true],
88
AutoMapper\Symfony\Bundle\AutoMapperBundle::class => ['all' => true],
99
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true],
10+
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
1011
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
1112
];

tests/Bundle/Resources/config/packages/automapper.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ automapper:
66
eval: false
77
reload_strategy: 'always'
88
api_platform: true
9+
doctrine: true
910
name_converter: AutoMapper\Tests\Bundle\Resources\App\Service\IdNameConverter
1011
map_private_properties: false
1112
check_attributes: false
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
doctrine:
2+
dbal:
3+
connections:
4+
default:
5+
driver: 'pdo_sqlite'
6+
path: '%kernel.project_dir%/var/data.db'
7+
default_connection: default
8+
orm:
9+
auto_generate_proxy_classes: true
10+
naming_strategy: doctrine.orm.naming_strategy.underscore
11+
auto_mapping: true
12+
mappings:
13+
App:
14+
type: attribute
15+
dir: '%kernel.project_dir%/App/Entity'
16+
prefix: 'App\Entity'
17+
alias: App

0 commit comments

Comments
 (0)