8000 [DependencyInjection] Add ContainerBuilder::isAvailable() to help wit… · symfony/symfony@bf4ca77 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf4ca77

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

File tree

19 files changed

+145
-115
lines changed

19 files changed

+145
-115
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->isAvailable('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/DebugBundle/DependencyInjection/Configuration.php

Lines changed: 6 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,22 +50,15 @@ public function getConfigTreeBuilder()
5150
->example('php://stderr, or tcp://%env(VAR_DUMPER_SERVER)% when using the "server:dump" command')
5251
->defaultNull()
5352
->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')
58+
->end()
5459
->end()
5560
;
5661

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()
66-
->end()
67-
;
68-
}
69-
7062
return $treeBuilder;
7163
}
7264
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function load(array $configs, ContainerBuilder $container)
4545
->addMethodCall('setMinDepth', [$config['min_depth']])
4646
->addMethodCall('setMaxString', [$config['max_string_length']]);
4747

48-
if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
48+
if ($container->isAvailable('symfony/var-dumper', ReflectionCaster::class, 'unsetClosureFileInfo')) {
4949
$container->getDefinition('var_dumper.cloner')
5050
->addMethodCall('addCasters', [ReflectionCaster::UNSET_CLOSURE_FILE_INFO]);
5151
}
5252

53-
if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
53+
if ($container->isAvailable('symfony/var-dumper', HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
5454
$container->getDefinition('var_dumper.html_dumper')
5555
->addMethodCall('setTheme', [$config['theme']]);
5656
}
@@ -84,15 +84,15 @@ public function load(array $configs, ContainerBuilder $container)
8484
;
8585
}
8686

87-
if (method_exists(CliDumper::class, 'setDisplayOptions')) {
87+
if ($container->isAvailable('symfony/var-dumper', CliDumper::class, 'setDisplayOptions')) {
8888
$container->getDefinition('var_dumper.cli_dumper')
8989
->addMethodCall('setDisplayOptions', [[
9090
'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
9191
]])
9292
;
9393
}
9494

95-
if (!class_exists(ServerLogCommand::class)) {
95+
if (!$container->isAvailable('symfony/monolog-bridge', ServerLogCommand::class)) {
9696
$container->removeDefinition('monolog.command.server_log');
9797
}
9898
}

src/Symfony/Bundle/DebugBundle/Resources/config/services.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
->set('monolog.command.server_log', ServerLogCommand::class)
135135
;
136136

137-
if (class_exists(ConsoleFormatter::class) && interface_exists(FormatterInterface::class)) {
137+
if ($container->isAvailable('symfony/monolog-bridge', ConsoleFormatter::class) && $container->isAvailable('monolog/monolog', FormatterInterface::class)) {
138138
$container->services()->get('monolog.command.server_log')->tag('console.command');
139139
}
140140
};

src/Symfony/Bundle/DebugBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
},
2525
"require-dev": {
2626
"symfony/config": "^4.4|^5.0",
27-
"symfony/dependency-injection": "^4.4|^5.0",
27+
"symfony/dependency-injection": "^5.3",
2828
"symfony/web-profiler-bundle": "^4.4|^5.0"
2929
},
3030
"conflict": {
3131
"symfony/config": "<4.4",
32-
"symfony/dependency-injection": "<5.2"
32+
"symfony/dependency-injection": "<5.3"
3333
},
3434
"suggest": {
3535
"symfony/config": "For service container configuration",

0 commit comments

Comments
 (0)
0