Skip to content

Commit 45c9df5

Browse files
[DI][FrameworkBundle] Add PSR-11 "ContainerBag" to access parameters as-a-service
1 parent e29926b commit 45c9df5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ CHANGELOG
44
4.1.0
55
-----
66

7-
* allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
7+
* Allowed to pass an optional `LoggerInterface $logger` instance to the `Router`
8+
* Added a new `parameter_bag` service with related autowiring aliases to acces parameters as-a-service
89

910
4.0.0
1011
-----

DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
3636
use Symfony\Component\DependencyInjection\Exception\LogicException;
3737
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
38+
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
39+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
3840
use Symfony\Component\DependencyInjection\Reference;
3941
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
4042
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -110,6 +112,12 @@ public function load(array $configs, ContainerBuilder $container)
110112
$loader->load('services.xml');
111113
$loader->load('fragment_renderer.xml');
112114

115+
if (!interface_exists(ContainerBagInterface::class)) {
116+
$container->removeDefinition('parameter_bag');
117+
$container->removeAlias(ContainerBagInterface::class);
118+
$container->removeAlias(ParameterBagInterface::class);
119+
}
120+
113121
if (class_exists(Application::class)) {
114122
$loader->load('console.xml');
115123

Resources/config/services.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<services>
88
<defaults public="false" />
99

10+
<service id="parameter_bag" class="Symfony\Component\DependencyInjection\ParameterBag\ContainerBag">
11+
<argument type="service" id="service_container" />
12+
</service>
13+
<service id="Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface" alias="parameter_bag" />
14+
<service id="Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface" alias="parameter_bag" />
15+
1016
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\EventDispatcher" public="true">
1117
<tag name="container.hot_path" />
1218
</service>

0 commit comments

Comments
 (0)