Skip to content

Commit c5b7b21

Browse files
[DependencyInjection] Add ContainerBuilder::willBeAvailable() to help with conditional configuration
1 parent 386555b commit c5b7b21

File tree

12 files changed

+124
-86
lines changed

12 files changed

+124
-86
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterUidTypePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class RegisterUidTypePass implements CompilerPassInterface
2424
*/
2525
public function process(ContainerBuilder $container)
2626
{
27-
if (!class_exists(AbstractUid::class)) {
27+
if (!$container->willBeAvailable('symfony/uid', AbstractUid::class)) {
2828
return;
2929
}
3030

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"symfony/stopwatch": "^4.4|^5.0",
3131
"symfony/cache": "^5.1",
3232
"symfony/config": "^4.4|^5.0",
33-
"symfony/dependency-injection": "^4.4|^5.0",
33+
"symfony/dependency-injection": "^5.3",
3434
"symfony/form": "^5.1.3",
3535
"symfony/http-kernel": "^5.0",
3636
"symfony/messenger": "^4.4|^5.0",
@@ -54,7 +54,7 @@
5454
"conflict": {
5555
"doctrine/dbal": "<2.10",
5656
"phpunit/phpunit": "<5.4.3",
57-
"symfony/dependency-injection": "<4.4",
57+
"symfony/dependency-injection": "<5.3",
5858
"symfony/form": "<5.1",
5959
"symfony/http-kernel": "<5",
6060
"symfony/messenger": "<4.4",

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

Lines changed: 75 additions & 65 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function load(array $configs, ContainerBuilder $container)
125125
$loader->load('security_legacy.php');
126126
}
127127

128-
if (class_exists(AbstractExtension::class)) {
128+
if ($container->willBeAvailable('twig/twig', AbstractExtension::class)) {
129129
$loader->load('templating_twig.php');
130130
}
131131

@@ -136,7 +136,7 @@ public function load(array $configs, ContainerBuilder $container)
136136
$loader->load('security_debug.php');
137137
}
138138

139-
if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
139+
if (!$container->willBeAvailable('symfony/expression-language', \Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
140140
$container->removeDefinition('security.expression_language');
141141
$container->removeDefinition('security.access.expression_voter');
142142
}
@@ -170,7 +170,7 @@ public function load(array $configs, ContainerBuilder $container)
170170
$this->createEncoders($config['encoders'], $container);
171171
}
172172

173-
if (class_exists(Application::class)) {
173+
if ($container->willBeAvailable('symfony/console', Application::class)) {
174174
$loader->load('console.php');
175175
$container->getDefinition('security.command.user_password_encoder')->replaceArgument(1, array_keys($config['encoders']));
176176
}
@@ -844,8 +844,8 @@ private function createExpression(ContainerBuilder $container, string $expressio
844844
return $this->expressions[$id];
845845
}
846846

847-
if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
848-
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
847+
if (!$container->willBeAvailable('symfony/expression-language', \Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
848+
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
849849
}
850850

851851
$container

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=7.2.5",
2020
"ext-xml": "*",
2121
"symfony/config": "^4.4|^5.0",
22-
"symfony/dependency-injection": "^5.2",
22+
"symfony/dependency-injection": "^5.3",
2323
"symfony/deprecation-contracts": "^2.1",
2424
"symfony/event-dispatcher": "^5.1",
2525
"symfony/http-kernel": "^5.0",

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ class ExtensionPass implements CompilerPassInterface
2323
{
2424
public function process(ContainerBuilder $container)
2525
{
26-
if (!class_exists(\Symfony\Component\Asset\Packages::class)) {
26+
if (!$container->willBeAvailable('symfony/asset', \Symfony\Component\Asset\Packages::class)) {
2727
$container->removeDefinition('twig.extension.assets');
2828
}
2929

30-
if (!class_exists(\Symfony\Component\ExpressionLanguage\Expression::class)) {
30+
if (!$container->willBeAvailable('symfony/expression-language', \Symfony\Component\ExpressionLanguage\Expression::class)) {
3131
$container->removeDefinition('twig.extension.expression');
3232
}
3333

34-
if (!interface_exists(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)) {
34+
if (!$container->willBeAvailable('symfony/routing', \Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)) {
3535
$container->removeDefinition('twig.extension.routing');
3636
}
3737

38-
if (!class_exists(\Symfony\Component\Yaml\Yaml::class)) {
38+
if (!$container->willBeAvailable('symfony/yaml', \Symfony\Component\Yaml\Yaml::class)) {
3939
$container->removeDefinition('twig.extension.yaml');
4040
}
4141

@@ -111,7 +111,7 @@ public function process(ContainerBuilder $container)
111111
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
112112
}
113113

114-
if (!class_exists(Workflow::class) || !$container->has('workflow.registry')) {
114+
if (!$container->willBeAvailable('symfony/workflow', Workflow::class) || !$container->has('workflow.registry')) {
115115
$container->removeDefinition('workflow.twig_extension');
116116
} else {
117117
$container->getDefinition('workflow.twig_extension')->addTag('twig.extension');

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public function load(array $configs, ContainerBuilder $container)
3737
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3838
$loader->load('twig.php');
3939

40-
if (class_exists(\Symfony\Component\Form\Form::class)) {
40+
if ($container->willBeAvailable('symfony/form', \Symfony\Component\Form\Form::class)) {
4141
$loader->load('form.php');
4242
}
4343

44-
if (class_exists(Application::class)) {
44+
if ($container->willBeAvailable('symfony/console', Application::class)) {
4545
$loader->load('console.php');
4646
}
4747

48-
if (class_exists(Mailer::class)) {
48+
if ($container->willBeAvailable('symfony/mailer', Mailer::class)) {
4949
$loader->load('mailer.php');
5050
}
5151

52-
if (!class_exists(Translator::class)) {
52+
if (!$container->willBeAvailable('symfony/translation', Translator::class)) {
5353
$container->removeDefinition('twig.translation.extractor');
5454
}
5555

src/Symfony/Bundle/TwigBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"require-dev": {
2828
"symfony/asset": "^4.4|^5.0",
2929
"symfony/stopwatch": "^4.4|^5.0",
30-
"symfony/dependency-injection": "^5.2",
30+
"symfony/dependency-injection": "^5.3",
3131
"symfony/expression-language": "^4.4|^5.0",
3232
"symfony/finder": "^4.4|^5.0",
3333
"symfony/form": "^4.4|^5.0",
@@ -40,7 +40,7 @@
4040
"doctrine/cache": "~1.0"
4141
},
4242
"conflict": {
43-
"symfony/dependency-injection": "<5.2",
43+
"symfony/dependency-injection": "<5.3",
4444
"symfony/framework-bundle": "<5.0",
4545
"symfony/translation": "<5.0"
4646
},

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `ServicesConfigurator::remove()` in the PHP-DSL
8+
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
89

910
5.2.0
1011
-----

src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private function getExpressionLanguage(): ExpressionLanguage
198198
{
199199
if (null === $this->expressionLanguage) {
200200
if (!class_exists(ExpressionLanguage::class)) {
201-
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
201+
throw new LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
202202
}
203203

204204
$providers = $this->container->getExpressionLanguageProviders();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy