@@ -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:[email protected] :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+ 
103133note ::
104134
105135    The ``server_version `` option was added in Doctrine DBAL 2.5, which
@@ -125,7 +155,9 @@ 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 ::
159+ 
160+     .. code-block :: yaml 
129161
130162
131163        dbal:
@@ -144,6 +176,29 @@ If you want to configure multiple connections in YAML, put them under the
144176                    host:             localhost
145177                    server_version:   '8.2.0'
146178
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+ 
147202database_connection `` service always refers to the *default * connection,
148203which is the first one defined or the one configured via the
149204``default_connection `` parameter.
@@ -172,7 +227,9 @@ 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 ::
231+ 
232+     .. code-block :: yaml 
176233
177234
178235        orm:
@@ -187,6 +244,29 @@ that the ORM resolves to:
187244            result_cache_driver: array
188245            naming_strategy: doctrine.orm.naming_strategy.default
189246
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()->type('array') 
259+                 ->queryCacheDriver()->type('array') 
260+                 ->resultCacheDriver()->type('array') 
261+                 ->namingStrategy('doctrine.orm.naming_strategy.default'); 
262+ 
263+             $orm 
264+                 ->autoGenerateProxyClasses(false) 
265+                 ->proxyNamespace('Proxies') 
266+                 ->proxyDir('%kernel.cache_dir%/doctrine/orm/Proxies') 
267+                 ->defaultEntityManager('default'); 
268+         }; 
269+ 
190270
191271certain classes, but those are for very advanced use-cases only.
192272
@@ -230,35 +310,70 @@ Caching Drivers
230310Use any of the existing :doc: `Symfony Cache  </cache >` pools or define new pools
231311to cache each of Doctrine ORM elements (queries, results, etc.):
232312
233- .. code -block  yaml 
313+ .. configuration -block
234314
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  
315+     .. code-block :: yaml 
243316
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  
317+         #  config/packages/prod/doctrine.yaml 
318+         framework : 
319+             cache : 
320+                 pools : 
321+                     doctrine.result_cache_pool : 
322+                         adapter : cache.app  
323+                     doctrine.system_cache_pool : 
324+                         adapter : cache.system  
256325
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  
326+         doctrine : 
327+             orm : 
328+                 #  ... 
329+                 metadata_cache_driver : 
330+                     type : pool  
331+                     pool : doctrine.system_cache_pool  
332+                 query_cache_driver : 
333+                     type : pool  
334+                     pool : doctrine.system_cache_pool  
335+                 result_cache_driver : 
336+                     type : pool  
337+                     pool : doctrine.result_cache_pool  
338+ 
339+                 #  in addition to Symfony cache pools, you can also use the 
340+                 #  'type: service' option to use any service as a cache pool 
341+                 query_cache_driver : 
342+                     type : service  
343+                     id : App\ORM\MyCacheService  
344+ 
345+ code-block :: php 
346+ 
347+         use Symfony\Config\DoctrineConfig; 
348+         use Symfony\Config\FrameworkConfig; 
349+ 
350+         return static function (FrameworkConfig $framework, DoctrineConfig $doctrine): void { 
351+             $framework 
352+                 ->cache() 
353+                     ->pool('doctrine.result_cache_pool') 
354+                         ->adapters('cache.app') 
355+                     ->pool('doctrine.system_cache_pool') 
356+                         ->adapters('cache.sytsem'); 
357+ 
358+             $doctrine->orm() 
359+                 // ... 
360+                 ->entityManager('default') 
361+                 ->metadataCacheDriver() 
362+                     ->type('pool') 
363+                     ->pool('doctrine.system_cache_pool') 
364+                 ->queryCacheDriver() 
365+                     ->type('pool') 
366+                     ->pool('doctrine.system_cache_pool') 
367+                 ->resultCacheDriver() 
368+                     ->type('pool') 
369+                     ->pool('doctrine.result_cache_pool') 
370+ 
371+                 // in addition to Symfony cache pools, you can also use the 
372+                 // 'type: service' option to use any service as a cache pool 
373+                 ->queryCacheDriver() 
374+                     ->type('service') 
375+                     ->id(App\ORM\MyCacheService::class); 
376+         }; 
262377
263378
264379~~~~~~~~~~~~~~~~~~~~~ 
0 commit comments