@@ -223,107 +223,46 @@ command:
223223
224224 $ php bin/console debug:autowiring
225225
226- If you need control over the *exact * value of an argument, you can :ref: `bind <services-binding >`
227- the argument by its name:
228-
229- .. configuration-block ::
230-
231- .. code-block :: yaml
232-
233- # config/services.yaml
234- services :
235- # ...
236-
237- # explicitly configure the service
238- App\Controller\LuckyController :
239- tags : [controller.service_arguments]
240- bind :
241- # for any $logger argument, pass this specific service
242- $logger : ' @monolog.logger.doctrine'
243- # for any $projectDir argument, pass this parameter value
244- $projectDir : ' %kernel.project_dir%'
245-
246- .. code-block :: xml
247-
248- <!-- config/services.xml -->
249- <?xml version =" 1.0" encoding =" UTF-8" ?>
250- <container xmlns =" http://symfony.com/schema/dic/services"
251- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
252- xsi : schemaLocation =" http://symfony.com/schema/dic/services
253- https://symfony.com/schema/dic/services/services-1.0.xsd" >
254-
255- <services >
256- <!-- ... -->
257-
258- <!-- Explicitly configure the service -->
259- <service id =" App\Controller\LuckyController" >
260- <tag name =" controller.service_arguments" />
261- <bind key =" $logger"
262- type =" service"
263- id =" monolog.logger.doctrine"
264- />
265- <bind key =" $projectDir" >%kernel.project_dir%</bind >
266- </service >
267- </services >
268- </container >
269-
270- .. code-block :: php
271-
272- // config/services.php
273- use App\Controller\LuckyController;
274- use Symfony\Component\DependencyInjection\Reference;
275-
276- $container->register(LuckyController::class)
277- ->addTag('controller.service_arguments')
278- ->setBindings([
279- '$logger' => new Reference('monolog.logger.doctrine'),
280- '$projectDir' => '%kernel.project_dir%',
281- ])
282- ;
283-
284- Like with all services, you can also use regular :ref: `constructor injection <services-constructor-injection >`
285- in your controllers.
286-
287- For more information about services, see the :doc: `/service_container ` article.
288-
289- Autowire Parameter Attribute
290- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291-
292- .. versionadded :: 6.1
226+ .. tip ::
293227
294- The ``#[Autowire] `` attribute was introduced in Symfony 6.1.
228+ If you need control over the *exact * value of an argument, you can use the
229+ ``#[Autowire] `` attribute::
295230
296- Services that cannot be autowired, :ref: `parameters <service-parameters >` and even
297- :doc: `complex expressions </service_container/expression_language >` can be bound
298- to a controller argument with the ``#[Autowire] `` attribute::
231+ // ...
232+ use Psr\Log\LoggerInterface;
233+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
234+ use Symfony\Component\HttpFoundation\Response;
299235
300- use Psr\Log\LoggerInterface;
301- use Symfony\Component\DependencyInjection\Attribute\Autowire;
302- use Symfony\Component\HttpFoundation\Response;
303- // ...
236+ class LuckyController extends AbstractController
237+ {
238+ public function number(
239+ int $max,
240+
241+ // inject a specific logger service
242+ #[Autowire('@monolog.logger.request')]
243+ LoggerInterface $logger,
244+
245+ // or inject parameter values
246+ #[Autowire('%kernel.project_dir%')]
247+ string $projectDir
248+ ): Response
249+ {
250+ $logger->info('We are logging!');
251+ // ...
252+ }
253+ }
304254
305- /**
306- * @Route("/lucky/number/{max}")
307- */
308- public function number(
309- int $max,
255+ You can read more about this attribute in :ref: `autowire-attribute `.
310256
311- #[Autowire('@monolog.logger.request')]
312- LoggerInterface $logger,
257+ .. versionadded :: 6.1
313258
314- #[Autowire('%kernel.project_dir%/data')]
315- string $dataDir,
259+ The ``#[Autowire] `` attribute was introduced in Symfony 6.1.
316260
317- #[Autowire('%kernel.debug%')]
318- bool $debugMode,
261+ Like with all services, you can also use regular
262+ :ref: `constructor injection <services-constructor-injection >` in your
263+ controllers.
319264
320- #[Autowire("@=service("App\\Mail\\MailerConfiguration").getMailerMethod()")]
321- string $mailerMethod,
322- ): Response
323- {
324- $logger->info('We are logging!');
325- // ...
326- }
265+ For more information about services, see the :doc: `/service_container ` article.
327266
328267Generating Controllers
329268----------------------
0 commit comments