Skip to content

Commit 75a1fd8

Browse files
committed
minor #10391 Documented the binding of arguments by name and type (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Documented the binding of arguments by name and type Fixes #10023. Commits ------- eea8c4c Documented the binding of arguments by name and type
2 parents 2617a7a + eea8c4c commit 75a1fd8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

service_container.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
655655
# service that's defined in this file
656656
Psr\Log\LoggerInterface: '@monolog.logger.request'
657657
658+
# optionally you can define both the name and type of the argument to match
659+
string $adminEmail: '[email protected]'
660+
Psr\Log\LoggerInterface $requestLogger: '@monolog.logger.request'
661+
658662
# ...
659663
660664
.. code-block:: xml
@@ -677,6 +681,13 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
677681
type="service"
678682
id="monolog.logger.request"
679683
/>
684+
685+
<!-- optionally you can define both the name and type of the argument to match -->
686+
<bind key="string $adminEmail">[email protected]</bind>
687+
<bind key="Psr\Log\LoggerInterface $requestLogger"
688+
type="service"
689+
id="monolog.logger.request"
690+
/>
680691
</defaults>
681692
682693
<!-- ... -->
@@ -696,12 +707,19 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
696707
'$adminEmail' => '[email protected]',
697708
'$requestLogger' => new Reference('monolog.logger.request'),
698709
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' => '[email protected]',
712+
LoggerInterface::class.' $requestLogger' => new Reference('monolog.logger.request'),
699713
))
700714
;
701715
702716
By putting the ``bind`` key under ``_defaults``, you can specify the value of *any*
703717
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.
705723

706724
The ``bind`` config can also be applied to specific services or when loading many
707725
services at once (i.e. :ref:`service-psr4-loader`).

0 commit comments

Comments
 (0)