Skip to content

[DependencyInjection][FrameworkBundle][SecurityBundle][TwigBundle] Require Composer's runtime API to be present #43788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"require": {
"php": ">=8.0.2",
"composer-runtime-api": ">=2.1",
"ext-xml": "*",
"friendsofphp/proxy-manager-lts": "^1.0.2",
"doctrine/event-manager": "~1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$parentPackages = (array) $parentPackage;
$parentPackages[] = 'symfony/framework-bundle';

return ContainerBuilder::willBeAvailable($package, $class, $parentPackages, true);
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages);
};

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.0.2",
"composer-runtime-api": ">=2.1",
"ext-xml": "*",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\SecurityBundle\DependencyInjection;

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

public function load(array $configs, ContainerBuilder $container)
{
if (!class_exists(InstalledVersions::class)) {
trigger_deprecation('symfony/security-bundle', '5.4', 'Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2.1 or later.');
}

if (!array_filter($configs)) {
return;
}
Expand All @@ -101,7 +96,7 @@ public function load(array $configs, ContainerBuilder $container)

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

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.0.2",
"composer-runtime-api": ">=2.1",
"ext-xml": "*",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\TwigBundle\DependencyInjection;

use Composer\InstalledVersions;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileExistenceResource;
use Symfony\Component\Console\Application;
Expand All @@ -36,26 +35,22 @@ class TwigExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
if (!class_exists(InstalledVersions::class)) {
trigger_deprecation('symfony/twig-bundle', '5.4', 'Configuring Symfony without the Composer Runtime API is deprecated. Consider upgrading to Composer 2.1 or later.');
}

$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('twig.php');

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/TwigBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.0.2",
"composer-runtime-api": ">=2.1",
"symfony/config": "^5.4|^6.0",
"symfony/twig-bridge": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
Expand Down
11 changes: 5 additions & 6 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,21 +1409,20 @@ public function log(CompilerPassInterface $pass, string $message)
*
* When parent packages are provided and if any of them is in dev-only mode,
* the class will be considered available even if it is also in dev-only mode.
*
* @throws \LogicException If dependencies have been installed with Composer 1
*/
final public static function willBeAvailable(string $package, string $class, array $parentPackages): bool
{
$skipDeprecation = 3 < \func_num_args() && func_get_arg(3);
$hasRuntimeApi = class_exists(InstalledVersions::class);

if (!$hasRuntimeApi && !$skipDeprecation) {
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__);
if (!class_exists(InstalledVersions::class)) {
throw new \LogicException(sprintf('Calling "%s" when dependencies have been installed with Composer 1 is not supported. Consider upgrading to Composer 2.', __METHOD__));
}

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

if (!$hasRuntimeApi || !InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, false)) {
if (!InstalledVersions::isInstalled($package) || InstalledVersions::isInstalled($package, false)) {
return true;
}

Expand Down