@@ -89,16 +89,18 @@ public function load(array $configs, ContainerBuilder $container)
89
89
$ loader ->load ('security.xml ' );
90
90
}
91
91
92
+ $ useDoctrine = isset ($ bundles ['DoctrineBundle ' ]) && class_exists (Version::class);
93
+
92
94
$ this ->registerMetadataConfiguration ($ container , $ loader , $ bundles , $ config ['loader_paths ' ]);
93
95
$ this ->registerOAuthConfiguration ($ container , $ config , $ loader );
94
96
$ this ->registerSwaggerConfiguration ($ container , $ config , $ loader );
95
97
$ this ->registerJsonLdConfiguration ($ formats , $ loader );
96
98
$ this ->registerJsonHalConfiguration ($ formats , $ loader );
97
99
$ this ->registerJsonProblemConfiguration ($ errorFormats , $ loader );
98
- $ this ->registerBundlesConfiguration ($ bundles , $ config , $ loader );
100
+ $ this ->registerBundlesConfiguration ($ bundles , $ config , $ loader, $ useDoctrine );
99
101
$ this ->registerCacheConfiguration ($ container );
100
- $ this ->registerDoctrineExtensionConfiguration ($ container , $ config );
101
- $ this ->registerHttpCache ($ container , $ config , $ loader );
102
+ $ this ->registerDoctrineExtensionConfiguration ($ container , $ config, $ useDoctrine );
103
+ $ this ->registerHttpCache ($ container , $ config , $ loader, $ useDoctrine );
102
104
}
103
105
104
106
/**
@@ -316,11 +318,12 @@ private function registerJsonProblemConfiguration(array $errorFormats, XmlFileLo
316
318
* @param string[] $bundles
317
319
* @param array $config
318
320
* @param XmlFileLoader $loader
321
+ * @param bool $useDoctrine
319
322
*/
320
- private function registerBundlesConfiguration (array $ bundles , array $ config , XmlFileLoader $ loader )
323
+ private function registerBundlesConfiguration (array $ bundles , array $ config , XmlFileLoader $ loader, bool $ useDoctrine )
321
324
{
322
325
// Doctrine ORM support
323
- if (isset ( $ bundles [ ' DoctrineBundle ' ]) && class_exists (Version::class) ) {
326
+ if ($ useDoctrine ) {
324
327
$ loader ->load ('doctrine_orm.xml ' );
325
328
}
326
329
@@ -357,28 +360,32 @@ private function registerCacheConfiguration(ContainerBuilder $container)
357
360
*
358
361
* @param ContainerBuilder $container
359
362
* @param array $config
363
+ * @param bool $useDoctrine
360
364
*/
361
- private function registerDoctrineExtensionConfiguration (ContainerBuilder $ container , array $ config )
365
+ private function registerDoctrineExtensionConfiguration (ContainerBuilder $ container , array $ config, bool $ useDoctrine )
362
366
{
363
- if (false === $ config ['eager_loading ' ]['enabled ' ]) {
364
- $ container ->removeDefinition ('api_platform.doctrine.orm.query_extension.eager_loading ' );
365
- $ container ->removeDefinition ('api_platform.doctrine.orm.query_extension.filter_eager_loading ' );
367
+ if (!$ useDoctrine || $ config ['eager_loading ' ]['enabled ' ]) {
368
+ return ;
366
369
}
370
+
371
+ $ container ->removeDefinition ('api_platform.doctrine.orm.query_extension.eager_loading ' );
372
+ $ container ->removeDefinition ('api_platform.doctrine.orm.query_extension.filter_eager_loading ' );
367
373
}
368
374
369
- private function registerHttpCache (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader )
375
+ private function registerHttpCache (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader, bool $ useDoctrine )
370
376
{
371
377
$ loader ->load ('http_cache.xml ' );
372
378
373
- if (true !== $ config ['http_cache ' ]['invalidation ' ]['enabled ' ]) {
374
- if ($ container ->has ('api_platform.doctrine.listener.http_cache.purge ' )) {
375
- $ container ->removeDefinition ('api_platform.doctrine.listener.http_cache.purge ' );
376
- }
377
-
379
+ if (!$ config ['http_cache ' ]['invalidation ' ]['enabled ' ]) {
378
380
return ;
379
381
}
380
382
383
+ if ($ useDoctrine ) {
384
+ $ loader ->load ('doctrine_orm_http_cache_purger.xml ' );
385
+ }
386
+
381
387
$ loader ->load ('http_cache_tags.xml ' );
388
+
382
389
if (!$ config ['http_cache ' ]['invalidation ' ]['varnish_urls ' ]) {
383
390
return ;
384
391
}
0 commit comments