@@ -296,7 +296,7 @@ made. To do that, you create a new class::
296
296
->addPart(
297
297
'Someone just updated the site. We told them: '.$happyMessage
298
298
);
299
-
299
+
300
300
return $this->mailer->send($message) > 0;
301
301
}
302
302
}
@@ -317,7 +317,7 @@ you can type-hint the new ``SiteUpdateManager`` class and use it::
317
317
if ($siteUpdateManager->notifyOfSiteUpdate()) {
318
318
$this->addFlash('success', 'Notification mail was sent successfully.');
319
319
}
320
-
320
+
321
321
// ...
322
322
}
323
323
@@ -690,6 +690,42 @@ argument for *any* service defined in this file! You can bind arguments by name
690
690
The ``bind `` config can be also be applied to specific services or when loading many
691
691
services at once (i.e. :ref: `service-psr4-loader `).
692
692
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
+
693
729
.. _services-autowire :
694
730
695
731
The autowire Option
0 commit comments