@@ -100,6 +100,36 @@ The following block shows all possible configuration keys:
100
100
</doctrine : config >
101
101
</container >
102
102
103
+ .. code-block :: php
104
+
105
+ use Symfony\Config\DoctrineConfig;
106
+
107
+ return static function (DoctrineConfig $doctrine): void {
108
+ $dbal = $doctrine->dbal();
109
+
110
+ $dbal = $dbal
111
+ ->connection('default')
112
+ ->dbname('database')
113
+ ->host('localhost')
114
+ ->port(1234)
115
+ ->user('user')
116
+ ->password('secret')
117
+ ->driver('pdo_mysql')
118
+ ->url('mysql://db_user:db_password@127.0.0.1:3306/db_name') // if the url option is specified, it will override the above config
119
+ ->driverClass(App\DBAL\MyDatabaseDriver::class) // the DBAL driverClass option
120
+ ->option('foo', 'bar') // the DBAL driverOptions option
121
+ ->path('%kernel.project_dir%/var/data/data.sqlite')
122
+ ->memory(true)
123
+ ->unixSocket('/tmp/mysql.sock')
124
+ ->wrapperClass(App\DBAL\MyConnectionWrapper::class) // the DBAL wrapperClass option
125
+ ->charset('utf8mb4')
126
+ ->logging('%kernel.debug%')
127
+ ->platformService(App\DBAL\MyDatabasePlatformService::class)
128
+ ->serverVersion('8.0.37')
129
+ ->mappingType('enum', 'string')
130
+ ->type('custom', App\DBAL\MyCustomType::class);
131
+ };
132
+
103
133
.. note ::
104
134
105
135
The ``server_version `` option was added in Doctrine DBAL 2.5, which
@@ -125,7 +155,9 @@ The following block shows all possible configuration keys:
125
155
If you want to configure multiple connections in YAML, put them under the
126
156
``connections `` key and give them a unique name:
127
157
128
- .. code-block :: yaml
158
+ .. configuration-block ::
159
+
160
+ .. code-block :: yaml
129
161
130
162
doctrine:
131
163
dbal:
@@ -144,6 +176,29 @@ If you want to configure multiple connections in YAML, put them under the
144
176
host: localhost
145
177
server_version: '8.2.0'
146
178
179
+ .. code-block :: php
180
+
181
+ use Symfony\Config\DoctrineConfig;
182
+
183
+ return static function (DoctrineConfig $doctrine): void {
184
+ $dbal = $doctrine->dbal();
185
+ $dbal->defaultConnection('default');
186
+
187
+ $dbal->connection('default')
188
+ ->dbname('Symfony')
189
+ ->user('root')
190
+ ->password('null')
191
+ ->host('localhost')
192
+ ->serverVersion('8.0.37');
193
+
194
+ $dbal->connection('customer')
195
+ ->dbname('customer')
196
+ ->user('root')
197
+ ->password('null')
198
+ ->host('localhost')
199
+ ->serverVersion('8.2.0');
200
+ };
201
+
147
202
The ``database_connection `` service always refers to the *default * connection,
148
203
which is the first one defined or the one configured via the
149
204
``default_connection `` parameter.
@@ -172,7 +227,9 @@ Doctrine ORM Configuration
172
227
This following configuration example shows all the configuration defaults
173
228
that the ORM resolves to:
174
229
175
- .. code-block :: yaml
230
+ .. configuration-block ::
231
+
232
+ .. code-block :: yaml
176
233
177
234
doctrine:
178
235
orm:
@@ -187,6 +244,32 @@ that the ORM resolves to:
187
244
result_cache_driver: array
188
245
naming_strategy: doctrine.orm.naming_strategy.default
189
246
247
+ .. code-block :: php
248
+
249
+ use Symfony\Config\DoctrineConfig;
250
+
251
+ return static function (DoctrineConfig $doctrine): void {
252
+ $orm = $doctrine->orm();
253
+
254
+ $orm
255
+ ->entityManager('default')
256
+ ->connection('default')
257
+ ->autoMapping(true)
258
+ ->metadataCacheDriver()
259
+ ->type('array')
260
+ ->queryCacheDriver()
261
+ ->type('array')
262
+ ->resultCacheDriver()
263
+ ->type('array')
264
+ ->namingStrategy('doctrine.orm.naming_strategy.default');
265
+
266
+ $orm
267
+ ->autoGenerateProxyClasses(false) // the standard distribution overrides this to be true in debug, false otherwise
268
+ ->proxyNamespace('Proxies')
269
+ ->proxyDir('%kernel.cache_dir%/doctrine/orm/Proxies')
270
+ ->defaultEntityManager('default');
271
+ };
272
+
190
273
There are lots of other configuration options that you can use to overwrite
191
274
certain classes, but those are for very advanced use-cases only.
192
275
@@ -230,35 +313,70 @@ Caching Drivers
230
313
Use any of the existing :doc: `Symfony Cache </cache >` pools or define new pools
231
314
to cache each of Doctrine ORM elements (queries, results, etc.):
232
315
233
- .. code -block :: yaml
316
+ .. configuration -block ::
234
317
235
- # config/packages/prod/doctrine.yaml
236
- framework :
237
- cache :
238
- pools :
239
- doctrine.result_cache_pool :
240
- adapter : cache.app
241
- doctrine.system_cache_pool :
242
- adapter : cache.system
318
+ .. code-block :: yaml
243
319
244
- doctrine :
245
- orm :
246
- # ...
247
- metadata_cache_driver :
248
- type : pool
249
- pool : doctrine.system_cache_pool
250
- query_cache_driver :
251
- type : pool
252
- pool : doctrine.system_cache_pool
253
- result_cache_driver :
254
- type : pool
255
- pool : doctrine.result_cache_pool
320
+ # config/packages/prod/doctrine.yaml
321
+ framework :
322
+ cache :
323
+ pools :
324
+ doctrine.result_cache_pool :
325
+ adapter : cache.app
326
+ doctrine.system_cache_pool :
327
+ adapter : cache.system
256
328
257
- # in addition to Symfony Cache pools, you can also use the
258
- # 'type: service' option to use any service as the cache
259
- query_cache_driver :
260
- type : service
261
- id : App\ORM\MyCacheService
329
+ doctrine :
330
+ orm :
331
+ # ...
332
+ metadata_cache_driver :
333
+ type : pool
334
+ pool : doctrine.system_cache_pool
335
+ query_cache_driver :
336
+ type : pool
337
+ pool : doctrine.system_cache_pool
338
+ result_cache_driver :
339
+ type : pool
340
+ pool : doctrine.result_cache_pool
341
+
342
+ # in addition to Symfony Cache pools, you can also use the
343
+ # 'type: service' option to use any service as the cache
344
+ query_cache_driver :
345
+ type : service
346
+ id : App\ORM\MyCacheService
347
+
348
+ .. code-block :: php
349
+
350
+ use Symfony\Config\DoctrineConfig;
351
+ use Symfony\Config\FrameworkConfig;w
352
+
353
+ return static function (FrameworkConfig $framework, DoctrineConfig $doctrine): void {
354
+ $framework
355
+ ->cache()
356
+ ->pool('doctrine.result_cache_pool')
357
+ ->adapters('cache.app')
358
+ ->pool('doctrine.system_cache_pool')
359
+ ->adapters('cache.sytsem');
360
+
361
+ $doctrine->orm()
362
+ // ...
363
+ ->entityManager('default')
364
+ ->metadataCacheDriver()
365
+ ->type('pool')
366
+ ->pool('doctrine.system_cache_pool')
367
+ ->queryCacheDriver()
368
+ ->type('pool')
369
+ ->pool('doctrine.system_cache_pool')
370
+ ->resultCacheDriver()
371
+ ->type('pool')
372
+ ->pool('doctrine.result_cache_pool')
373
+
374
+ // in addition to Symfony Cache pools, you can also use the
375
+ // 'type: service' option to use any service as the cache
376
+ ->queryCacheDriver()
377
+ ->type('service')
378
+ ->id(App\ORM\MyCacheService::class);
379
+ };
262
380
263
381
Mapping Configuration
264
382
~~~~~~~~~~~~~~~~~~~~~
0 commit comments