11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \DependencyInjection ;
13
13
14
+ use Composer \InstalledVersions ;
14
15
use Doctrine \Common \Annotations \AnnotationRegistry ;
15
16
use Doctrine \Common \Annotations \Reader ;
16
17
use Http \Client \HttpClient ;
@@ -234,14 +235,18 @@ class FrameworkExtension extends Extension
234
235
*/
235
236
public function load (array $ configs , ContainerBuilder $ container )
236
237
{
238
+ if (!class_exists (InstalledVersions::class)) {
239
+ trigger_deprecation ('symfony/framework-bundle ' , '5.4 ' , 'Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2. ' );
240
+ }
241
+
237
242
$ loader = new PhpFileLoader ($ container , new FileLocator (\dirname (__DIR__ ).'/Resources/config ' ));
238
243
239
244
$ loader ->load ('web.php ' );
240
245
$ loader ->load ('services.php ' );
241
246
$ loader ->load ('fragment_renderer.php ' );
242
247
$ loader ->load ('error_renderer.php ' );
243
248
244
- if (ContainerBuilder::willBeAvailable ('psr/event-dispatcher ' , PsrEventDispatcherInterface::class, ['symfony/framework-bundle ' ])) {
249
+ if (ContainerBuilder::willBeAvailable ('psr/event-dispatcher ' , PsrEventDispatcherInterface::class, ['symfony/framework-bundle ' ], true )) {
245
250
$ container ->setAlias (PsrEventDispatcherInterface::class, 'event_dispatcher ' );
246
251
}
247
252
@@ -288,11 +293,11 @@ public function load(array $configs, ContainerBuilder $container)
288
293
$ container ->getDefinition ('response_listener ' )->replaceArgument (1 , $ config ['set_content_language_from_locale ' ]);
289
294
290
295
// If the slugger is used but the String component is not available, we should throw an error
291
- if (!ContainerBuilder::willBeAvailable ('symfony/string ' , SluggerInterface::class, ['symfony/framework-bundle ' ])) {
296
+ if (!ContainerBuilder::willBeAvailable ('symfony/string ' , SluggerInterface::class, ['symfony/framework-bundle ' ], true )) {
292
297
$ container ->register ('slugger ' , 'stdClass ' )
293
298
->addError ('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string". ' );
294
299
} else {
295
- if (!ContainerBuilder::willBeAvailable ('symfony/translation ' , LocaleAwareInterface::class, ['symfony/framework-bundle ' ])) {
300
+ if (!ContainerBuilder::willBeAvailable ('symfony/translation ' , LocaleAwareInterface::class, ['symfony/framework-bundle ' ], true )) {
296
301
$ container ->register ('slugger ' , 'stdClass ' )
297
302
->addError ('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation". ' );
298
303
}
@@ -348,7 +353,7 @@ public function load(array $configs, ContainerBuilder $container)
348
353
}
349
354
350
355
if (null === $ config ['csrf_protection ' ]['enabled ' ]) {
351
- $ config ['csrf_protection ' ]['enabled ' ] = $ this ->sessionConfigEnabled && !class_exists (FullStack::class) && ContainerBuilder::willBeAvailable ('symfony/security-csrf ' , CsrfTokenManagerInterface::class, ['symfony/framework-bundle ' ]);
356
+ $ config ['csrf_protection ' ]['enabled ' ] = $ this ->sessionConfigEnabled && !class_exists (FullStack::class) && ContainerBuilder::willBeAvailable ('symfony/security-csrf ' , CsrfTokenManagerInterface::class, ['symfony/framework-bundle ' ], true );
352
357
}
353
358
$ this ->registerSecurityCsrfConfiguration ($ config ['csrf_protection ' ], $ container , $ loader );
354
359
@@ -360,7 +365,7 @@ public function load(array $configs, ContainerBuilder $container)
360
365
$ this ->formConfigEnabled = true ;
361
366
$ this ->registerFormConfiguration ($ config , $ container , $ loader );
362
367
363
- if (ContainerBuilder::willBeAvailable ('symfony/validator ' , Validation::class, ['symfony/framework-bundle ' , 'symfony/form ' ])) {
368
+ if (ContainerBuilder::willBeAvailable ('symfony/validator ' , Validation::class, ['symfony/framework-bundle ' , 'symfony/form ' ], true )) {
364
369
$ config ['validation ' ]['enabled ' ] = true ;
365
370
} else {
366
371
$ container ->setParameter ('validator.translation_domain ' , 'validators ' );
@@ -492,7 +497,7 @@ public function load(array $configs, ContainerBuilder $container)
492
497
'Symfony \\Bundle \\FrameworkBundle \\Controller \\AbstractController ' ,
493
498
]);
494
499
495
- if (ContainerBuilder::willBeAvailable ('symfony/mime ' , MimeTypes::class, ['symfony/framework-bundle ' ])) {
500
+ if (ContainerBuilder::willBeAvailable ('symfony/mime ' , MimeTypes::class, ['symfony/framework-bundle ' ], true )) {
496
501
$ loader ->load ('mime_type.php ' );
497
502
}
498
503
@@ -647,7 +652,7 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
647
652
$ container ->setParameter ('form.type_extension.csrf.enabled ' , false );
648
653
}
649
654
650
- if (!ContainerBuilder::willBeAvailable ('symfony/translation ' , Translator::class, ['symfony/framework-bundle ' , 'symfony/form ' ])) {
655
+ if (!ContainerBuilder::willBeAvailable ('symfony/translation ' , Translator::class, ['symfony/framework-bundle ' , 'symfony/form ' ], true )) {
651
656
$ container ->removeDefinition ('form.type_extension.upload.validator ' );
652
657
}
653
658
if (!method_exists (CachingFactoryDecorator::class, 'reset ' )) {
@@ -1038,7 +1043,7 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
1038
1043
$ container ->getDefinition ('routing.loader ' )->replaceArgument (2 , ['_locale ' => $ enabledLocales ]);
1039
1044
}
1040
1045
1041
- if (!ContainerBuilder::willBeAvailable ('symfony/expression-language ' , ExpressionLanguage::class, ['symfony/framework-bundle ' , 'symfony/routing ' ])) {
1046
+ if (!ContainerBuilder::willBeAvailable ('symfony/expression-language ' , ExpressionLanguage::class, ['symfony/framework-bundle ' , 'symfony/routing ' ], true )) {
1042
1047
$ container ->removeDefinition ('router.expression_language_provider ' );
1043
1048
}
1044
1049
@@ -1285,17 +1290,17 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
1285
1290
$ dirs = [];
1286
1291
$ transPaths = [];
1287
1292
$ nonExistingDirs = [];
1288
- if (ContainerBuilder::willBeAvailable ('symfony/validator ' , Validation::class, ['symfony/framework-bundle ' , 'symfony/translation ' ])) {
1293
+ if (ContainerBuilder::willBeAvailable ('symfony/validator ' , Validation::class, ['symfony/framework-bundle ' , 'symfony/translation ' ], true )) {
1289
1294
$ r = new \ReflectionClass (Validation::class);
1290
1295
1291
1296
$ dirs [] = $ transPaths [] = \dirname ($ r ->getFileName ()).'/Resources/translations ' ;
1292
1297
}
1293
- if (ContainerBuilder::willBeAvailable ('symfony/form ' , Form::class, ['symfony/framework-bundle ' , 'symfony/translation ' ])) {
1298
+ if (ContainerBuilder::willBeAvailable ('symfony/form ' , Form::class, ['symfony/framework-bundle ' , 'symfony/translation ' ], true )) {
1294
1299
$ r = new \ReflectionClass (Form::class);
1295
1300
1296
1301
$ dirs [] = $ transPaths [] = \dirname ($ r ->getFileName ()).'/Resources/translations ' ;
1297
1302
}
1298
- if (ContainerBuilder::willBeAvailable ('symfony/security-core ' , AuthenticationException::class, ['symfony/framework-bundle ' , 'symfony/translation ' ])) {
1303
+ if (ContainerBuilder::willBeAvailable ('symfony/security-core ' , AuthenticationException::class, ['symfony/framework-bundle ' , 'symfony/translation ' ], true )) {
1299
1304
$ r = new \ReflectionClass (AuthenticationException::class);
1300
1305
1301
1306
$ dirs [] = $ transPaths [] = \dirname ($ r ->getFileName (), 2 ).'/Resources/translations ' ;
@@ -1400,7 +1405,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
1400
1405
foreach ($ classToServices as $ class => $ service ) {
1401
1406
$ package = substr ($ service , \strlen ('translation.provider_factory. ' ));
1402
1407
1403
- if (!$ container ->hasDefinition ('http_client ' ) || !ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-translation-provider ' , $ package ), $ class , $ parentPackages )) {
1408
+ if (!$ container ->hasDefinition ('http_client ' ) || !ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-translation-provider ' , $ package ), $ class , $ parentPackages, true )) {
1404
1409
$ container ->removeDefinition ($ service );
1405
1410
}
1406
1411
}
@@ -1517,7 +1522,7 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
1517
1522
$ files ['yaml ' === $ extension ? 'yml ' : $ extension ][] = $ path ;
1518
1523
};
1519
1524
1520
- if (ContainerBuilder::willBeAvailable ('symfony/form ' , Form::class, ['symfony/framework-bundle ' , 'symfony/validator ' ])) {
1525
+ if (ContainerBuilder::willBeAvailable ('symfony/form ' , Form::class, ['symfony/framework-bundle ' , 'symfony/validator ' ], true )) {
1521
1526
$ reflClass = new \ReflectionClass (Form::class);
1522
1527
$ fileRecorder ('xml ' , \dirname ($ reflClass ->getFileName ()).'/Resources/config/validation.xml ' );
1523
1528
}
@@ -1688,7 +1693,7 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
1688
1693
throw new InvalidArgumentException (sprintf ('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed. ' , $ config ['decryption_env_var ' ]));
1689
1694
}
1690
1695
1691
- if (ContainerBuilder::willBeAvailable ('symfony/string ' , LazyString::class, ['symfony/framework-bundle ' ])) {
1696
+ if (ContainerBuilder::willBeAvailable ('symfony/string ' , LazyString::class, ['symfony/framework-bundle ' ], true )) {
1692
1697
$ container ->getDefinition ('secrets.decryption_key ' )->replaceArgument (1 , $ config ['decryption_env_var ' ]);
1693
1698
} else {
1694
1699
$ container ->getDefinition ('secrets.vault ' )->replaceArgument (1 , "%env( {$ config ['decryption_env_var ' ]})% " );
@@ -1828,7 +1833,7 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
1828
1833
1829
1834
$ loader ->load ('property_info.php ' );
1830
1835
1831
- if (ContainerBuilder::willBeAvailable ('phpdocumentor/reflection-docblock ' , DocBlockFactoryInterface::class, ['symfony/framework-bundle ' , 'symfony/property-info ' ])) {
1836
+ if (ContainerBuilder::willBeAvailable ('phpdocumentor/reflection-docblock ' , DocBlockFactoryInterface::class, ['symfony/framework-bundle ' , 'symfony/property-info ' ], true )) {
1832
1837
$ definition = $ container ->register ('property_info.php_doc_extractor ' , 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor ' );
1833
1838
$ definition ->addTag ('property_info.description_extractor ' , ['priority ' => -1000 ]);
1834
1839
$ definition ->addTag ('property_info.type_extractor ' , ['priority ' => -1001 ]);
@@ -1909,19 +1914,19 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
1909
1914
1910
1915
$ loader ->load ('messenger.php ' );
1911
1916
1912
- if (ContainerBuilder::willBeAvailable ('symfony/amqp-messenger ' , AmqpTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ])) {
1917
+ if (ContainerBuilder::willBeAvailable ('symfony/amqp-messenger ' , AmqpTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ], true )) {
1913
1918
$ container ->getDefinition ('messenger.transport.amqp.factory ' )->addTag ('messenger.transport_factory ' );
1914
1919
}
1915
1920
1916
- if (ContainerBuilder::willBeAvailable ('symfony/redis-messenger ' , RedisTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ])) {
1921
+ if (ContainerBuilder::willBeAvailable ('symfony/redis-messenger ' , RedisTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ], true )) {
1917
1922
$ container ->getDefinition ('messenger.transport.redis.factory ' )->addTag ('messenger.transport_factory ' );
1918
1923
}
1919
1924
1920
- if (ContainerBuilder::willBeAvailable ('symfony/amazon-sqs-messenger ' , AmazonSqsTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ])) {
1925
+ if (ContainerBuilder::willBeAvailable ('symfony/amazon-sqs-messenger ' , AmazonSqsTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ], true )) {
1921
1926
$ container ->getDefinition ('messenger.transport.sqs.factory ' )->addTag ('messenger.transport_factory ' );
1922
1927
}
1923
1928
1924
- if (ContainerBuilder::willBeAvailable ('symfony/beanstalkd-messenger ' , BeanstalkdTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ])) {
1929
+ if (ContainerBuilder::willBeAvailable ('symfony/beanstalkd-messenger ' , BeanstalkdTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/messenger ' ], true )) {
1925
1930
$ container ->getDefinition ('messenger.transport.beanstalkd.factory ' )->addTag ('messenger.transport_factory ' );
1926
1931
}
1927
1932
@@ -2247,12 +2252,12 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
2247
2252
unset($ options ['retry_failed ' ]);
2248
2253
$ container ->getDefinition ('http_client ' )->setArguments ([$ options , $ config ['max_host_connections ' ] ?? 6 ]);
2249
2254
2250
- if (!$ hasPsr18 = ContainerBuilder::willBeAvailable ('psr/http-client ' , ClientInterface::class, ['symfony/framework-bundle ' , 'symfony/http-client ' ])) {
2255
+ if (!$ hasPsr18 = ContainerBuilder::willBeAvailable ('psr/http-client ' , ClientInterface::class, ['symfony/framework-bundle ' , 'symfony/http-client ' ], true )) {
2251
2256
$ container ->removeDefinition ('psr18.http_client ' );
2252
2257
$ container ->removeAlias (ClientInterface::class);
2253
2258
}
2254
2259
2255
- if (!ContainerBuilder::willBeAvailable ('php-http/httplug ' , HttpClient::class, ['symfony/framework-bundle ' , 'symfony/http-client ' ])) {
2260
+ if (!ContainerBuilder::willBeAvailable ('php-http/httplug ' , HttpClient::class, ['symfony/framework-bundle ' , 'symfony/http-client ' ], true )) {
2256
2261
$ container ->removeDefinition (HttpClient::class);
2257
2262
}
2258
2263
@@ -2385,7 +2390,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
2385
2390
foreach ($ classToServices as $ class => $ service ) {
2386
2391
$ package = substr ($ service , \strlen ('mailer.transport_factory. ' ));
2387
2392
2388
- if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-mailer ' , 'gmail ' === $ package ? 'google ' : $ package ), $ class , ['symfony/framework-bundle ' , 'symfony/mailer ' ])) {
2393
+ if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-mailer ' , 'gmail ' === $ package ? 'google ' : $ package ), $ class , ['symfony/framework-bundle ' , 'symfony/mailer ' ], true )) {
2389
2394
$ container ->removeDefinition ($ service );
2390
2395
}
2391
2396
}
@@ -2527,25 +2532,25 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
2527
2532
case 'turbosms ' : $ package = 'turbo-sms ' ; break ;
2528
2533
}
2529
2534
2530
- if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-notifier ' , $ package ), $ class , $ parentPackages )) {
2535
+ if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-notifier ' , $ package ), $ class , $ parentPackages, true )) {
2531
2536
$ container ->removeDefinition ($ service );
2532
2537
}
2533
2538
}
2534
2539
2535
- if (ContainerBuilder::willBeAvailable ('symfony/mercure-notifier ' , MercureTransportFactory::class, $ parentPackages ) && ContainerBuilder::willBeAvailable ('symfony/mercure-bundle ' , MercureBundle::class, $ parentPackages )) {
2540
+ if (ContainerBuilder::willBeAvailable ('symfony/mercure-notifier ' , MercureTransportFactory::class, $ parentPackages, true ) && ContainerBuilder::willBeAvailable ('symfony/mercure-bundle ' , MercureBundle::class, $ parentPackages, true )) {
2536
2541
$ container ->getDefinition ($ classToServices [MercureTransportFactory::class])
2537
2542
->replaceArgument ('$registry ' , new Reference (HubRegistry::class));
2538
- } elseif (ContainerBuilder::willBeAvailable ('symfony/mercure-notifier ' , MercureTransportFactory::class, $ parentPackages )) {
2543
+ } elseif (ContainerBuilder::willBeAvailable ('symfony/mercure-notifier ' , MercureTransportFactory::class, $ parentPackages, true )) {
2539
2544
$ container ->removeDefinition ($ classToServices [MercureTransportFactory::class]);
2540
2545
}
2541
2546
2542
- if (ContainerBuilder::willBeAvailable ('symfony/fake-chat-notifier ' , FakeChatTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/notifier ' , 'symfony/mailer ' ])) {
2547
+ if (ContainerBuilder::willBeAvailable ('symfony/fake-chat-notifier ' , FakeChatTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/notifier ' , 'symfony/mailer ' ], true )) {
2543
2548
$ container ->getDefinition ($ classToServices [FakeChatTransportFactory::class])
2544
2549
->replaceArgument ('$mailer ' , new Reference ('mailer ' ))
2545
2550
->replaceArgument ('$logger ' , new Reference ('logger ' ));
2546
2551
}
2547
2552
2548
- if (ContainerBuilder::willBeAvailable ('symfony/fake-sms-notifier ' , FakeSmsTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/notifier ' , 'symfony/mailer ' ])) {
2553
+ if (ContainerBuilder::willBeAvailable ('symfony/fake-sms-notifier ' , FakeSmsTransportFactory::class, ['symfony/framework-bundle ' , 'symfony/notifier ' , 'symfony/mailer ' ], true )) {
2549
2554
$ container ->getDefinition ($ classToServices [FakeSmsTransportFactory::class])
2550
2555
->replaceArgument ('$mailer ' , new Reference ('mailer ' ))
2551
2556
->replaceArgument ('$logger ' , new Reference ('logger ' ));
0 commit comments