@@ -296,7 +296,7 @@ made. To do that, you create a new class::
296296 ->addPart(
297297 'Someone just updated the site. We told them: '.$happyMessage
298298 );
299-
299+
300300 return $this->mailer->send($message) > 0;
301301 }
302302 }
@@ -317,7 +317,7 @@ you can type-hint the new ``SiteUpdateManager`` class and use it::
317317 if ($siteUpdateManager->notifyOfSiteUpdate()) {
318318 $this->addFlash('success', 'Notification mail was sent successfully.');
319319 }
320-
320+
321321 // ...
322322 }
323323
@@ -690,6 +690,42 @@ argument for *any* service defined in this file! You can bind arguments by name
690690The ``bind `` config can be also be applied to specific services or when loading many
691691services at once (i.e. :ref: `service-psr4-loader `).
692692
693+ Getting Container Parameters as a Service
694+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
695+
696+ .. versionadded :: 4.1
697+ The feature to get container parameters as a service was introduced in Symfony 4.1.
698+
699+ If some service or controller needs lots of container parameters, there's an
700+ easier alternative to binding all of them with the ``services._defaults.bind ``
701+ option. Type-hint any of its constructor arguments with the
702+ :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ParameterBagInterface `
703+ or the new :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ContainerBagInterface `
704+ and the service will get all container parameters in a
705+ :class: `Symfony\\ Component\\ DependencyInjection\\ ParameterBag\\ ParameterBag ` object::
706+
707+ // src/Service/MessageGenerator.php
708+ // ...
709+
710+ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
711+
712+ class MessageGenerator
713+ {
714+ private $params;
715+
716+ public function __construct(ParameterBagInterface $params)
717+ {
718+ $this->params = $params;
719+ }
720+
721+ public function someMethod()
722+ {
723+ // get any param from $this->params, which stores all container parameters
724+ $sender = $this->params->get('mailer_sender');
725+ // ...
726+ }
727+ }
728+
693729.. _services-autowire :
694730
695731The autowire Option
0 commit comments