@@ -655,6 +655,10 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
655
655
# service that's defined in this file
656
656
Psr\Log\LoggerInterface : ' @monolog.logger.request'
657
657
658
+ # optionally you can define both the name and type of the argument to match
659
+ string $adminEmail : ' manager@example.com'
660
+ Psr\Log\LoggerInterface $requestLogger : ' @monolog.logger.request'
661
+
658
662
# ...
659
663
660
664
.. code-block :: xml
@@ -677,6 +681,13 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
677
681
type =" service"
678
682
id =" monolog.logger.request"
679
683
/>
684
+
685
+ <!-- optionally you can define both the name and type of the argument to match -->
686
+ <bind key =" string $adminEmail" >manager@example.com</bind >
687
+ <bind key =" Psr\Log\LoggerInterface $requestLogger"
688
+ type =" service"
689
+ id =" monolog.logger.request"
690
+ />
680
691
</defaults >
681
692
682
693
<!-- ... -->
@@ -696,12 +707,19 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
696
707
'$adminEmail' => 'manager@example.com',
697
708
'$requestLogger' => new Reference('monolog.logger.request'),
698
709
LoggerInterface::class => new Reference('monolog.logger.request'),
710
+ // optionally you can define both the name and type of the argument to match
711
+ 'string $adminEmail' => 'manager@example.com',
712
+ LoggerInterface::class.' $requestLogger' => new Reference('monolog.logger.request'),
699
713
))
700
714
;
701
715
702
716
By putting the ``bind `` key under ``_defaults ``, you can specify the value of *any *
703
717
argument for *any * service defined in this file! You can bind arguments by name
704
- (e.g. ``$adminEmail ``) or by type (e.g. ``Psr\Log\LoggerInterface ``).
718
+ (e.g. ``$adminEmail ``), by type (e.g. ``Psr\Log\LoggerInterface ``) or both
719
+ (e.g. ``Psr\Log\LoggerInterface $requestLogger ``).
720
+
721
+ .. versionadded :: 4.2
722
+ The feature to bind arguments by name and type was introduced in Symfony 4.2.
705
723
706
724
The ``bind `` config can also be applied to specific services or when loading many
707
725
services at once (i.e. :ref: `service-psr4-loader `).
0 commit comments