@@ -100,6 +100,36 @@ The following block shows all possible configuration keys:
100100 </doctrine : config >
101101 </container >
102102
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('5.7')
129+ ->mappingType('enum', 'string')
130+ ->type('custom', App\DBAL\MyCustomType::class);
131+ };
132+
103133 .. note ::
104134
105135 The ``server_version `` option was added in Doctrine DBAL 2.5, which
@@ -125,24 +155,49 @@ The following block shows all possible configuration keys:
125155If you want to configure multiple connections in YAML, put them under the
126156``connections `` key and give them a unique name:
127157
128- .. code -block :: yaml
158+ .. configuration -block ::
129159
130- doctrine :
131- dbal :
132- default_connection : default
133- connections :
134- default :
135- dbname : Symfony
136- user : root
137- password : null
138- host : localhost
139- server_version : ' 5.6'
140- customer :
141- dbname : customer
142- user : root
143- password : null
144- host : localhost
145- server_version : ' 5.7'
160+ .. code-block :: yaml
161+
162+ doctrine :
163+ dbal :
164+ default_connection : default
165+ connections :
166+ default :
167+ dbname : Symfony
168+ user : root
169+ password : null
170+ host : localhost
171+ server_version : ' 5.6'
172+ customer :
173+ dbname : customer
174+ user : root
175+ password : null
176+ host : localhost
177+ server_version : ' 5.7'
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('5.6');
193+
194+ $dbal->connection('customer')
195+ ->dbname('customer')
196+ ->user('root')
197+ ->password('null')
198+ ->host('localhost')
199+ ->serverVersion('5.7');
200+ };
146201
147202 The ``database_connection `` service always refers to the *default * connection,
148203which is the first one defined or the one configured via the
@@ -172,20 +227,48 @@ Doctrine ORM Configuration
172227This following configuration example shows all the configuration defaults
173228that the ORM resolves to:
174229
175- .. code -block :: yaml
230+ .. configuration -block ::
176231
177- doctrine :
178- orm :
179- auto_mapping : true
180- # the standard distribution overrides this to be true in debug, false otherwise
181- auto_generate_proxy_classes : false
182- proxy_namespace : Proxies
183- proxy_dir : ' %kernel.cache_dir%/doctrine/orm/Proxies'
184- default_entity_manager : default
185- metadata_cache_driver : array
186- query_cache_driver : array
187- result_cache_driver : array
188- naming_strategy : doctrine.orm.naming_strategy.default
232+ .. code-block :: yaml
233+
234+ doctrine :
235+ orm :
236+ auto_mapping : true
237+ # the standard distribution overrides this to be true in debug, false otherwise
238+ auto_generate_proxy_classes : false
239+ proxy_namespace : Proxies
240+ proxy_dir : ' %kernel.cache_dir%/doctrine/orm/Proxies'
241+ default_entity_manager : default
242+ metadata_cache_driver : array
243+ query_cache_driver : array
244+ result_cache_driver : array
245+ naming_strategy : doctrine.orm.naming_strategy.default
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+ };
189272
190273 There are lots of other configuration options that you can use to overwrite
191274certain classes, but those are for very advanced use-cases only.
@@ -230,35 +313,70 @@ Caching Drivers
230313Use any of the existing :doc: `Symfony Cache </cache >` pools or define new pools
231314to cache each of Doctrine ORM elements (queries, results, etc.):
232315
233- .. code -block :: yaml
316+ .. configuration -block ::
234317
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
243319
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
256328
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+ };
262380
263381 Mapping Configuration
264382~~~~~~~~~~~~~~~~~~~~~
0 commit comments