@@ -153,7 +153,7 @@ and ``redirect()`` methods::
153
153
154
154
// redirects to a route and maintains the original query string parameters
155
155
return $this->redirectToRoute('blog_show', $request->query->all());
156
-
156
+
157
157
// redirects to the current route (e.g. for Post/Redirect/Get pattern):
158
158
return $this->redirectToRoute($request->attributes->get('_route'));
159
159
@@ -223,66 +223,44 @@ command:
223
223
224
224
$ php bin/console debug:autowiring
225
225
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.
226
+ .. tip ::
227
+
228
+ If you need control over the *exact * value of an argument, you can use the
229
+ ``#[Autowire] `` attribute::
230
+
231
+ // ...
232
+ use Psr\Log\LoggerInterface;
233
+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
234
+ use Symfony\Component\HttpFoundation\Response;
235
+
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
+ }
254
+
255
+ You can read more about this attribute in :ref: `autowire-attribute `.
256
+
257
+ .. versionadded :: 6.1
258
+
259
+ The ``#[Autowire] `` attribute was introduced in Symfony 6.1.
260
+
261
+ Like with all services, you can also use regular
262
+ :ref: `constructor injection <services-constructor-injection >` in your
263
+ controllers.
286
264
287
265
For more information about services, see the :doc: `/service_container ` article.
288
266
0 commit comments