Skip to content

Commit 4ec2e99

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

File tree

12 files changed

+176
-117
lines changed

12 files changed

+176
-117
lines changed

src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
1515
use Symfony\Component\Config\Definition\ConfigurationInterface;
16-
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
1716

1817
/**
1918
* DebugExtension configuration structure.
@@ -51,21 +50,13 @@ public function getConfigTreeBuilder()
5150
->example('php://stderr, or tcp://%env(VAR_DUMPER_SERVER)% when using the "server:dump" command')
5251
->defaultNull()
5352
->end()
54-
->end()
55-
;
56-
57-
if (method_exists(HtmlDumper::class, 'setTheme')) {
58-
$rootNode
59-
->children()
60-
->enumNode('theme')
61-
->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"')
62-
->example('dark')
63-
->values(['dark', 'light'])
64-
->defaultValue('dark')
65-
->end()
53+
->enumNode('theme')
54+
->info('Changes the color of the dump() output when rendered directly on the templating. "dark" (default) or "light"')
55+
->example('dark')
56+
->values(['dark', 'light'])
57+
->defaultValue('dark')
6658
->end()
6759
;
68-
}
6960

7061
return $treeBuilder;
7162
}

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

Lines changed: 64 additions & 50 deletions
Large diffs are not rendered by default.

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

Lines changed: 52 additions & 35 deletions
Large diffs are not rendered by default.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ protected static function getBundleDefaultConfig()
442442
'mapping' => ['paths' => []],
443443
],
444444
'property_access' => [
445+
'enabled' => true,
445446
'magic_call' => false,
446447
'magic_get' => true,
447448
'magic_set' => true,

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

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

1212
namespace Symfony\Bundle\SecurityBundle\DependencyInjection;
1313

14+
use Symfony\Bridge\Twig\Extension\LogoutUrlExtension;
1415
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
1516
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface;
1617
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\RememberMeFactory;
@@ -31,14 +32,14 @@
3132
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
3233
use Symfony\Component\DependencyInjection\Reference;
3334
use Symfony\Component\EventDispatcher\EventDispatcher;
35+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
3436
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
3537
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
3638
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
3739
use Symfony\Component\Security\Core\Encoder\SodiumPasswordEncoder;
3840
use Symfony\Component\Security\Core\User\ChainUserProvider;
3941
use Symfony\Component\Security\Core\User\UserProviderInterface;
4042
use Symfony\Component\Security\Http\Event\CheckPassportEvent;
41-
use Twig\Extension\AbstractExtension;
4243

4344
/**
4445
* SecurityExtension.
@@ -125,7 +126,7 @@ public function load(array $configs, ContainerBuilder $container)
125126
$loader->load('security_legacy.php');
126127
}
127128

128-
if (class_exists(AbstractExtension::class)) {
129+
if ($container::willBeAvailable('symfony/twig-bridge', LogoutUrlExtension::class, ['symfony/security-bundle'])) {
129130
$loader->load('templating_twig.php');
130131
}
131132

@@ -136,7 +137,7 @@ public function load(array $configs, ContainerBuilder $container)
136137
$loader->load('security_debug.php');
137138
}
138139

139-
if (!class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) {
140+
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'])) {
140141
$container->removeDefinition('security.expression_language');
141142
$container->removeDefinition('security.access.expression_voter');
142143
}
@@ -844,8 +845,8 @@ private function createExpression(ContainerBuilder $container, string $expressio
844845
return $this->expressions[$id];
845846
}
846847

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.');
848+
if (!$container::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/security-bundle'])) {
849+
throw new \RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
849850
}
850851

851852
$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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\Asset\Packages;
1415
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\ExpressionLanguage\Expression;
19+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1720
use Symfony\Component\Workflow\Workflow;
21+
use Symfony\Component\Yaml\Yaml;
1822

1923
/**
2024
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
@@ -23,19 +27,19 @@ class ExtensionPass implements CompilerPassInterface
2327
{
2428
public function process(ContainerBuilder $container)
2529
{
26-
if (!class_exists(\Symfony\Component\Asset\Packages::class)) {
30+
if (!$container::willBeAvailable('symfony/asset', Packages::class, ['symfony/twig-bundle'])) {
2731
$container->removeDefinition('twig.extension.assets');
2832
}
2933

30-
if (!class_exists(\Symfony\Component\ExpressionLanguage\Expression::class)) {
34+
if (!$container::willBeAvailable('symfony/expression-language', Expression::class, ['symfony/twig-bundle'])) {
3135
$container->removeDefinition('twig.extension.expression');
3236
}
3337

34-
if (!interface_exists(\Symfony\Component\Routing\Generator\UrlGeneratorInterface::class)) {
38+
if (!$container::willBeAvailable('symfony/routing', UrlGeneratorInterface::class, ['symfony/twig-bundle'])) {
3539
$container->removeDefinition('twig.extension.routing');
3640
}
3741

38-
if (!class_exists(\Symfony\Component\Yaml\Yaml::class)) {
42+
if (!$container::willBeAvailable('symfony/yaml', Yaml::class, ['symfony/twig-bundle'])) {
3943
$container->removeDefinition('twig.extension.yaml');
4044
}
4145

@@ -111,7 +115,7 @@ public function process(ContainerBuilder $container)
111115
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
112116
}
113117

114-
if (!class_exists(Workflow::class) || !$container->has('workflow.registry')) {
118+
if (!$container::willBeAvailable('symfony/workflow', Workflow::class, ['symfony/twig-bundle']) || !$container->has('workflow.registry')) {
115119
$container->removeDefinition('workflow.twig_extension');
116120
} else {
117121
$container->getDefinition('workflow.twig_extension')->addTag('twig.extension');

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\Form\Form;
2021
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2122
use Symfony\Component\Mailer\Mailer;
2223
use Symfony\Component\Translation\Translator;
@@ -37,19 +38,19 @@ public function load(array $configs, ContainerBuilder $container)
3738
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
3839
$loader->load('twig.php');
3940

40-
if (class_exists(\Symfony\Component\Form\Form::class)) {
41+
if ($container::willBeAvailable('symfony/form', Form::class, ['symfony/twig-bundle'])) {
4142
$loader->load('form.php');
4243
}
4344

44-
if (class_exists(Application::class)) {
45+
if ($container::willBeAvailable('symfony/console', Application::class, ['symfony/twig-bundle'])) {
4546
$loader->load('console.php');
4647
}
4748

48-
if (class_exists(Mailer::class)) {
49+
if ($container::willBeAvailable('symfony/mailer', Mailer::class, ['symfony/twig-bundle'])) {
4950
$loader->load('mailer.php');
5051
}
5152

52-
if (!class_exists(Translator::class)) {
53+
if (!$container::willBeAvailable('symfony/translation', Translator::class, ['symfony/twig-bundle'])) {
5354
$container->removeDefinition('twig.translation.extractor');
5455
}
5556

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
-----

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