Skip to content

Commit 290f5ea

Browse files
committed
Deprecate Composer 1
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent f3a4c10 commit 290f5ea

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function getConfigTreeBuilder()
126126
$parentPackages = (array) $parentPackage;
127127
$parentPackages[] = 'symfony/framework-bundle';
128128

129-
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages);
129+
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages, true);
130130
};
131131

132132
$enableIfStandalone = static function (string $package, string $class) use ($willBeAvailable) {

DependencyInjection/FrameworkExtension.php

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

14+
use Composer\InstalledVersions;
1415
use Doctrine\Common\Annotations\AnnotationRegistry;
1516
use Doctrine\Common\Annotations\Reader;
1617
use Http\Client\HttpClient;
@@ -234,14 +235,18 @@ class FrameworkExtension extends Extension
234235
*/
235236
public function load(array $configs, ContainerBuilder $container)
236237
{
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+
237242
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
238243

239244
$loader->load('web.php');
240245
$loader->load('services.php');
241246
$loader->load('fragment_renderer.php');
242247
$loader->load('error_renderer.php');
243248

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)) {
245250
$container->setAlias(PsrEventDispatcherInterface::class, 'event_dispatcher');
246251
}
247252

@@ -288,11 +293,11 @@ public function load(array $configs, ContainerBuilder $container)
288293
$container->getDefinition('response_listener')->replaceArgument(1, $config['set_content_language_from_locale']);
289294

290295
// 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)) {
292297
$container->register('slugger', 'stdClass')
293298
->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
294299
} else {
295-
if (!ContainerBuilder::willBeAvailable('symfony/translation', LocaleAwareInterface::class, ['symfony/framework-bundle'])) {
300+
if (!ContainerBuilder::willBeAvailable('symfony/translation', LocaleAwareInterface::class, ['symfony/framework-bundle'], true)) {
296301
$container->register('slugger', 'stdClass')
297302
->addError('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation".');
298303
}
@@ -348,7 +353,7 @@ public function load(array $configs, ContainerBuilder $container)
348353
}
349354

350355
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);
352357
}
353358
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
354359

@@ -360,7 +365,7 @@ public function load(array $configs, ContainerBuilder $container)
360365
$this->formConfigEnabled = true;
361366
$this->registerFormConfiguration($config, $container, $loader);
362367

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)) {
364369
$config['validation']['enabled'] = true;
365370
} else {
366371
$container->setParameter('validator.translation_domain', 'validators');
@@ -492,7 +497,7 @@ public function load(array $configs, ContainerBuilder $container)
492497
'Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController',
493498
]);
494499

495-
if (ContainerBuilder::willBeAvailable('symfony/mime', MimeTypes::class, ['symfony/framework-bundle'])) {
500+
if (ContainerBuilder::willBeAvailable('symfony/mime', MimeTypes::class, ['symfony/framework-bundle'], true)) {
496501
$loader->load('mime_type.php');
497502
}
498503

@@ -647,7 +652,7 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
647652
$container->setParameter('form.type_extension.csrf.enabled', false);
648653
}
649654

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)) {
651656
$container->removeDefinition('form.type_extension.upload.validator');
652657
}
653658
if (!method_exists(CachingFactoryDecorator::class, 'reset')) {
@@ -1038,7 +1043,7 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
10381043
$container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]);
10391044
}
10401045

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)) {
10421047
$container->removeDefinition('router.expression_language_provider');
10431048
}
10441049

@@ -1285,17 +1290,17 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12851290
$dirs = [];
12861291
$transPaths = [];
12871292
$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)) {
12891294
$r = new \ReflectionClass(Validation::class);
12901295

12911296
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
12921297
}
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)) {
12941299
$r = new \ReflectionClass(Form::class);
12951300

12961301
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
12971302
}
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)) {
12991304
$r = new \ReflectionClass(AuthenticationException::class);
13001305

13011306
$dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
@@ -1400,7 +1405,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
14001405
foreach ($classToServices as $class => $service) {
14011406
$package = substr($service, \strlen('translation.provider_factory.'));
14021407

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)) {
14041409
$container->removeDefinition($service);
14051410
}
14061411
}
@@ -1517,7 +1522,7 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
15171522
$files['yaml' === $extension ? 'yml' : $extension][] = $path;
15181523
};
15191524

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)) {
15211526
$reflClass = new \ReflectionClass(Form::class);
15221527
$fileRecorder('xml', \dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
15231528
}
@@ -1688,7 +1693,7 @@ private function registerSecretsConfiguration(array $config, ContainerBuilder $c
16881693
throw new InvalidArgumentException(sprintf('Invalid value "%s" set as "decryption_env_var": only "word" characters are allowed.', $config['decryption_env_var']));
16891694
}
16901695

1691-
if (ContainerBuilder::willBeAvailable('symfony/string', LazyString::class, ['symfony/framework-bundle'])) {
1696+
if (ContainerBuilder::willBeAvailable('symfony/string', LazyString::class, ['symfony/framework-bundle'], true)) {
16921697
$container->getDefinition('secrets.decryption_key')->replaceArgument(1, $config['decryption_env_var']);
16931698
} else {
16941699
$container->getDefinition('secrets.vault')->replaceArgument(1, "%env({$config['decryption_env_var']})%");
@@ -1828,7 +1833,7 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
18281833

18291834
$loader->load('property_info.php');
18301835

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)) {
18321837
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
18331838
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
18341839
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
@@ -1909,19 +1914,19 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
19091914

19101915
$loader->load('messenger.php');
19111916

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)) {
19131918
$container->getDefinition('messenger.transport.amqp.factory')->addTag('messenger.transport_factory');
19141919
}
19151920

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)) {
19171922
$container->getDefinition('messenger.transport.redis.factory')->addTag('messenger.transport_factory');
19181923
}
19191924

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)) {
19211926
$container->getDefinition('messenger.transport.sqs.factory')->addTag('messenger.transport_factory');
19221927
}
19231928

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)) {
19251930
$container->getDefinition('messenger.transport.beanstalkd.factory')->addTag('messenger.transport_factory');
19261931
}
19271932

@@ -2247,12 +2252,12 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
22472252
unset($options['retry_failed']);
22482253
$container->getDefinition('http_client')->setArguments([$options, $config['max_host_connections'] ?? 6]);
22492254

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)) {
22512256
$container->removeDefinition('psr18.http_client');
22522257
$container->removeAlias(ClientInterface::class);
22532258
}
22542259

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)) {
22562261
$container->removeDefinition(HttpClient::class);
22572262
}
22582263

@@ -2385,7 +2390,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
23852390
foreach ($classToServices as $class => $service) {
23862391
$package = substr($service, \strlen('mailer.transport_factory.'));
23872392

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)) {
23892394
$container->removeDefinition($service);
23902395
}
23912396
}
@@ -2527,25 +2532,25 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
25272532
case 'turbosms': $package = 'turbo-sms'; break;
25282533
}
25292534

2530-
if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $class, $parentPackages)) {
2535+
if (!ContainerBuilder::willBeAvailable(sprintf('symfony/%s-notifier', $package), $class, $parentPackages, true)) {
25312536
$container->removeDefinition($service);
25322537
}
25332538
}
25342539

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)) {
25362541
$container->getDefinition($classToServices[MercureTransportFactory::class])
25372542
->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)) {
25392544
$container->removeDefinition($classToServices[MercureTransportFactory::class]);
25402545
}
25412546

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)) {
25432548
$container->getDefinition($classToServices[FakeChatTransportFactory::class])
25442549
->replaceArgument('$mailer', new Reference('mailer'))
25452550
->replaceArgument('$logger', new Reference('logger'));
25462551
}
25472552

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)) {
25492554
$container->getDefinition($classToServices[FakeSmsTransportFactory::class])
25502555
->replaceArgument('$mailer', new Reference('mailer'))
25512556
->replaceArgument('$logger', new Reference('logger'));

0 commit comments

Comments
 (0)