Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0865ede

Browse filesBrowse files
committed
feature #43788 [DependencyInjection][FrameworkBundle][SecurityBundle][TwigBundle] Require Composer's runtime API to be present (derrabus)
This PR was merged into the 6.0 branch. Discussion ---------- [DependencyInjection][FrameworkBundle][SecurityBundle][TwigBundle] Require Composer's runtime API to be present | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Recently, I was asked to help debugging a strange behavior of my client's app that surfaced only on some developer machines while others were fine. Turns out, a particular package was installed as a dev dependency (which was fine because we used it for dev tooling only at that time) and the difference between the environments was that the broken ones used Composer 2. With `ContainerBuilder::willBeAvailable()`, we have introduced logic into the very heart of the framework that exposes significantly different behavior for Composer 1 and 2. With this PR, I'd like to propose to make Composer's runtime API a requirement, essentially making the use of Composer 2 a requirement. Composer 2 has been released over a year ago and by now every developer should have been able to upgrade to version 2. I don't think that this constraint would push the ecosystem too hard. Let's make everyone's lives easier by moving on to Composer 2. Commits ------- e08b362 Require Composer's runtime API to be present
2 parents b813347 + e08b362 commit 0865ede
Copy full SHA for 0865ede

File tree

9 files changed

+44
-56
lines changed
Filter options

9 files changed

+44
-56
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"require": {
3535
"php": ">=8.0.2",
36+
"composer-runtime-api": ">=2.1",
3637
"ext-xml": "*",
3738
"friendsofphp/proxy-manager-lts": "^1.0.2",
3839
"doctrine/event-manager": "~1.0",

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getConfigTreeBuilder(): TreeBuilder
122122
$parentPackages = (array) $parentPackage;
123123
$parentPackages[] = 'symfony/framework-bundle';
124124

125-
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages, true);
125+
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages);
126126
};
127127

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

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+27-32Lines changed: 27 additions & 32 deletions
Large diffs are not rendered by default.

‎src/Symfony/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.0.2",
20+
"composer-runtime-api": ">=2.1",
2021
"ext-xml": "*",
2122
"symfony/cache": "^5.4|^6.0",
2223
"symfony/config": "^5.4|^6.0",

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection;
1313

14-
use Composer\InstalledVersions;
1514
use Symfony\Bridge\Twig\Extension\LogoutUrlExtension;
1615
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
1716
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface;
@@ -76,10 +75,6 @@ public function prepend(ContainerBuilder $container)
7675

7776
public function load(array $configs, ContainerBuilder $container)
7877
{
79-
if (!class_exists(InstalledVersions::class)) {
80-
trigger_deprecation('symfony/security-bundle', '5.4', 'Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2.1 or later.');
81-
}
82-
8378
if (!array_filter($configs)) {
8479
return;
8580
}
@@ -101,7 +96,7 @@ public function load(array $configs, ContainerBuilder $container)
10196

10297
$loader->load('security_authenticator.php');
10398

104-
if ($container::willBeAvailable('symfony/twig-bridge', LogoutUrlExtension::class, ['symfony/security-bundle'], true)) {
99+
if ($container::willBeAvailable('symfony/twig-bridge', LogoutUrlExtension::class, ['symfony/security-bundle'])) {
105100
$loader->load('templating_twig.php');
106101
}
107102

@@ -111,7 +106,7 @@ public function load(array $configs, ContainerBuilder $container)
111106
$loader->load('security_debug.php');
112107
}
113108

114-
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'], true)) {
109+
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'])) {
115110
$container->removeDefinition('security.expression_language');
116111
$container->removeDefinition('security.access.expression_voter');
117112
}
@@ -831,7 +826,7 @@ private function createExpression(ContainerBuilder $container, string $expressio
831826
return $this->expressions[$id];
832827
}
833828

834-
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'], true)) {
829+
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'])) {
835830
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
836831
}
837832

‎src/Symfony/Bundle/SecurityBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.0.2",
20+
"composer-runtime-api": ">=2.1",
2021
"ext-xml": "*",
2122
"symfony/config": "^5.4|^6.0",
2223
"symfony/dependency-injection": "^5.4|^6.0",

‎src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php
+4-9Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection;
1313

14-
use Composer\InstalledVersions;
1514
use Symfony\Component\Config\FileLocator;
1615
use Symfony\Component\Config\Resource\FileExistenceResource;
1716
use Symfony\Component\Console\Application;
@@ -36,26 +35,22 @@ class TwigExtension extends Extension
3635
{
3736
public function load(array $configs, ContainerBuilder $container)
3837
{
39-
if (!class_exists(InstalledVersions::class)) {
40-
trigger_deprecation('symfony/twig-bundle', '5.4', 'Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2.1 or later.');
41-
}
42-
4338
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
4439
$loader->load('twig.php');
4540

46-
if ($container::willBeAvailable('symfony/form', Form::class, ['symfony/twig-bundle'], true)) {
41+
if ($container::willBeAvailable('symfony/form', Form::class, ['symfony/twig-bundle'])) {
4742
$loader->load('form.php');
4843
}
4944

50-
if ($container::willBeAvailable('symfony/console', Application::class, ['symfony/twig-bundle'], true)) {
45+
if ($container::willBeAvailable('symfony/console', Application::class, ['symfony/twig-bundle'])) {
5146
$loader->load('console.php');
5247
}
5348

54-
if ($container::willBeAvailable('symfony/mailer', Mailer::class, ['symfony/twig-bundle'], true)) {
49+
if ($container::willBeAvailable('symfony/mailer', Mailer::class, ['symfony/twig-bundle'])) {
5550
$loader->load('mailer.php');
5651
}
5752

58-
if (!$container::willBeAvailable('symfony/translation', Translator::class, ['symfony/twig-bundle'], true)) {
53+
if (!$container::willBeAvailable('symfony/translation', Translator::class, ['symfony/twig-bundle'])) {
5954
$container->removeDefinition('twig.translation.extractor');
6055
}
6156

‎src/Symfony/Bundle/TwigBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.0.2",
20+
"composer-runtime-api": ">=2.1",
2021
"symfony/config": "^5.4|^6.0",
2122
"symfony/twig-bridge": "^5.4|^6.0",
2223
"symfony/http-foundation": "^5.4|^6.0",

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,21 +1409,20 @@ public function log(CompilerPassInterface $pass, string $message)
14091409
*
14101410
* When parent packages are provided and if any of them is in dev-only mode,
14111411
* the class will be considered available even if it is also in dev-only mode.
1412+
*
1413+
* @throws \LogicException If dependencies have been installed with Composer 1
14121414
*/
14131415
final public static function willBeAvailable(string $package, string $class, array $parentPackages): bool
14141416
{
1415-
$skipDeprecation = 3 < \func_num_args() && func_get_arg(3);
1416-
$hasRuntimeApi = class_exists(InstalledVersions::class);
1417-
1418-
if (!$hasRuntimeApi && !$skipDeprecation) {
1419-
trigger_deprecation('symfony/dependency-injection', '5.4', 'Calling "%s" when dependencies have been installed with Composer 1 is deprecated. Consider upgrading to Composer 2.', __METHOD__);
1417+
if (!class_exists(InstalledVersions::class)) {
1418+
throw new \LogicException(sprintf('Calling "%s" when dependencies have been installed with Composer 1 is not supported. Consider upgrading to Composer 2.', __METHOD__));
14201419
}
14211420

14221421
if (!class_exists($class) && !interface_exists($class, false) && !trait_exists($class, false)) {
14231422
return false;
14241423
}
14251424

1426-
if (!$hasRuntimeApi || !InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, false)) {
1425+
if (!InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, false)) {
14271426
return true;
14281427
}
14291428

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.