Skip to content

Commit 533945c

Browse files
committed
updating controller scalar args for 3.4
1 parent 892e501 commit 533945c

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

controller.rst

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ command:
275275
276276
$ php bin/console debug:autowiring
277277
278-
If you need control over the *exact* value of an argument, you can override your
279-
controller's service config:
278+
If you need control over the *exact* value of an argument, you can :ref:`bind <services-binding>`
279+
the argument by its name:
280280

281281
.. configuration-block::
282282

@@ -289,13 +289,9 @@ controller's service config:
289289
# explicitly configure the service
290290
AppBundle\Controller\LuckyController:
291291
public: true
292-
tags:
293-
# add multiple tags to control multiple args
294-
- name: controller.service_arguments
295-
action: numberAction
296-
argument: logger
297-
# pass this specific service id
298-
id: monolog.logger.doctrine
292+
bind:
293+
# for any $logger argument, pass this specific service
294+
$logger: '@monolog.logger.doctrine'
299295
300296
.. code-block:: xml
301297
@@ -311,10 +307,8 @@ controller's service config:
311307
312308
<!-- Explicitly configure the service -->
313309
<service id="AppBundle\Controller\LuckyController" public="true">
314-
<tag
315-
name="controller.service_arguments"
316-
action="numberAction"
317-
argument="logger"
310+
<bind key="$logger"
311+
type="service"
318312
id="monolog.logger.doctrine"
319313
/>
320314
</service>
@@ -325,25 +319,25 @@ controller's service config:
325319
326320
// app/config/services.php
327321
use AppBundle\Controller\LuckyController;
322+
use Symfony\Component\DependencyInjection\Reference;
328323
329324
$container->register(LuckyController::class)
330325
->setPublic(true)
331-
->addTag('controller.service_arguments', [
332-
'action' => 'numberAction',
333-
'argument' => 'logger',
334-
'id' => 'monolog.logger.doctrine',
335-
])
326+
->setBindings(array(
327+
'$logger' => new Reference('monolog.logger.doctrine'),
328+
))
336329
;
337330
338331
You can of course also use normal :ref:`constructor injection <services-constructor-injection>`
339332
in your controllers.
340333

341334
.. caution::
342335

343-
You can *only* pass *services* to your controller arguments in this way. It's
344-
not possible, for example, to pass a service parameter as a controller argument.
345-
If you need a parameter, use the ``$this->getParameter('kernel.debug')`` shortcut
346-
or pass the value through your controller's ``__construct()`` method.
336+
You can *only* pass *services* to your controller arguments in this way. It's not
337+
possible, for example, to pass a service parameter as a controller argument,
338+
even by using ``bind``. If you need a parameter, use the ``$this->getParameter('kernel.debug')``
339+
shortcut or pass the value through your controller's ``__construct()`` method
340+
and specify its value with ``bind``.
347341

348342
For more information about services, see the :doc:`/service_container` article.
349343

service_container.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ service whose id is ``monolog.logger.request``.
690690
the *service* whose id is ``monolog.logger.request``, and not just the *string*
691691
``monolog.logger.request``.
692692

693+
.. _services-binding:
694+
695+
Binding Arguments by Name or Type
696+
---------------------------------
697+
698+
You can also use the ``bind`` keyword to bind specific arguments by name or type.
699+
693700
.. _services-autowire:
694701

695702
The autowire Option

0 commit comments

Comments
 (0)