Skip to content

Commit bd0595e

Browse files
committed
minor #17755 [Doctrine] Cleaning up the config code samples (ThomasLandauer)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Doctrine] Cleaning up the config code samples Page: https://symfony.com/doc/5.4/doctrine/multiple_entity_managers.html Things I've changed: 1. Moved `defaultConnection` downwards (YAML & PHP). Setting the default *before* defining any connection looked awkward. 2. Removed `driver`, `server_version`, `charset`. As I see it on https://symfony.com/doc/current/doctrine.html#configuring-the-database, the recommended way is to set this inside `.env`. Besides, it distracts from the important points here. 3. Renamed `DATABASE_CUSTOMER_URL` to `CUSTOMER_DATABASE_URL` - in accordance with the way the dependency injection works: `EntityManagerInterface $customerEntityManager`. Plus renaming `emDefault` to `defaultEntityManager` in PHP config. Commits ------- 3d635b6 [Doctrine] Cleaning up the config code samples
2 parents 3a4b017 + 3d635b6 commit bd0595e

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

doctrine/multiple_entity_managers.rst

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. index::
22
single: Doctrine; Multiple entity managers
33

4-
How to Work with multiple Entity Managers and Connections
4+
How to Work with Multiple Entity Managers and Connections
55
=========================================================
66

77
You can use multiple Doctrine entity managers or connections in a Symfony
@@ -32,20 +32,12 @@ The following configuration code shows how you can configure two entity managers
3232
# config/packages/doctrine.yaml
3333
doctrine:
3434
dbal:
35-
default_connection: default
3635
connections:
3736
default:
38-
# configure these for your database server
3937
url: '%env(resolve:DATABASE_URL)%'
40-
driver: 'pdo_mysql'
41-
server_version: '5.7'
42-
charset: utf8mb4
4338
customer:
44-
# configure these for your database server
45-
url: '%env(resolve:DATABASE_CUSTOMER_URL)%'
46-
driver: 'pdo_mysql'
47-
server_version: '5.7'
48-
charset: utf8mb4
39+
url: '%env(resolve:CUSTOMER_DATABASE_URL)%'
40+
default_connection: default
4941
orm:
5042
default_entity_manager: default
5143
entity_managers:
@@ -82,20 +74,12 @@ The following configuration code shows how you can configure two entity managers
8274
8375
<doctrine:config>
8476
<doctrine:dbal default-connection="default">
85-
<!-- configure these for your database server -->
8677
<doctrine:connection name="default"
8778
url="%env(resolve:DATABASE_URL)%"
88-
driver="pdo_mysql"
89-
server_version="5.7"
90-
charset="utf8mb4"
9179
/>
9280
93-
<!-- configure these for your database server -->
9481
<doctrine:connection name="customer"
95-
url="%env(resolve:DATABASE_CUSTOMER_URL)%"
96-
driver="pdo_mysql"
97-
server_version="5.7"
98-
charset="utf8mb4"
82+
url="%env(resolve:CUSTOMER_DATABASE_URL)%"
9983
/>
10084
</doctrine:dbal>
10185
@@ -131,37 +115,28 @@ The following configuration code shows how you can configure two entity managers
131115
use Symfony\Config\DoctrineConfig;
132116
133117
return static function (DoctrineConfig $doctrine) {
134-
$doctrine->dbal()->defaultConnection('default');
135-
136-
// configure these for your database server
118+
// Connections:
137119
$doctrine->dbal()
138120
->connection('default')
139-
->url(env('DATABASE_URL')->resolve())
140-
->driver('pdo_mysql')
141-
->serverVersion('5.7')
142-
->charset('utf8mb4');
143-
144-
// configure these for your database server
121+
->url(env('DATABASE_URL')->resolve());
145122
$doctrine->dbal()
146123
->connection('customer')
147-
->url(env('DATABASE_CUSTOMER_URL')->resolve())
148-
->driver('pdo_mysql')
149-
->serverVersion('5.7')
150-
->charset('utf8mb4');
151-
124+
->url(env('CUSTOMER_DATABASE_URL')->resolve());
125+
$doctrine->dbal()->defaultConnection('default');
126+
127+
// Entity Managers:
152128
$doctrine->orm()->defaultEntityManager('default');
153-
$emDefault = $doctrine->orm()->entityManager('default');
154-
$emDefault->connection('default');
155-
$emDefault->mapping('Main')
129+
$defaultEntityManager = $doctrine->orm()->entityManager('default');
130+
$defaultEntityManager->connection('default');
131+
$defaultEntityManager->mapping('Main')
156132
->isBundle(false)
157133
->type('annotation')
158134
->dir('%kernel.project_dir%/src/Entity/Main')
159135
->prefix('App\Entity\Main')
160136
->alias('Main');
161-
162-
$emCustomer = $doctrine->orm()->entityManager('customer');
163-
$emCustomer->connection('customer');
164-
$emCustomer->mapping('Customer')
137+
$customerEntityManager = $doctrine->orm()->entityManager('customer');
138+
$customerEntityManager->connection('customer');
139+
$customerEntityManager->mapping('Customer')
165140
->isBundle(false)
166141
->type('annotation')
167142
->dir('%kernel.project_dir%/src/Entity/Customer')

0 commit comments

Comments
 (0)