@@ -275,8 +275,8 @@ command:
275
275
276
276
$ php bin/console debug:autowiring
277
277
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 :
280
280
281
281
.. configuration-block ::
282
282
@@ -289,13 +289,9 @@ controller's service config:
289
289
# explicitly configure the service
290
290
AppBundle\Controller\LuckyController :
291
291
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'
299
295
300
296
.. code-block :: xml
301
297
@@ -311,10 +307,8 @@ controller's service config:
311
307
312
308
<!-- Explicitly configure the service -->
313
309
<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"
318
312
id =" monolog.logger.doctrine"
319
313
/>
320
314
</service >
@@ -325,25 +319,25 @@ controller's service config:
325
319
326
320
// app/config/services.php
327
321
use AppBundle\Controller\LuckyController;
322
+ use Symfony\Component\DependencyInjection\Reference;
328
323
329
324
$container->register(LuckyController::class)
330
325
->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
+ ))
336
329
;
337
330
338
331
You can of course also use normal :ref: `constructor injection <services-constructor-injection >`
339
332
in your controllers.
340
333
341
334
.. caution ::
342
335
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 ``.
347
341
348
342
For more information about services, see the :doc: `/service_container ` article.
349
343
0 commit comments