@@ -39,6 +39,19 @@ create its object:
39
39
40
40
..configuration-block ::
41
41
42
+ ..code-block ::php-attributes
43
+
44
+ // src/Email/NewsletterManager.php
45
+ namespace App\Email;
46
+
47
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
48
+
49
+ // the first argument is the class and the second argument is the static method
50
+ #[Autoconfigure(factory: ['App\Email\NewsletterManagerStaticFactory', 'createNewsletterManager'])]
51
+ class NewsletterManager
52
+ {
53
+ }
54
+
42
55
..code-block ::yaml
43
56
44
57
# config/services.yaml
@@ -121,6 +134,18 @@ You can omit the class on the factory declaration:
121
134
122
135
..configuration-block ::
123
136
137
+ ..code-block ::php-attributes
138
+
139
+ // src/Email/NewsletterManager.php
140
+ namespace App\Email;
141
+
142
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
143
+
144
+ #[Autoconfigure(bind: ['$sender' => 'fabien@symfony.com'], factory: [null, 'createNewsletterManager'])]
145
+ class NewsletterManager
146
+ {
147
+ }
148
+
124
149
..code-block ::yaml
125
150
126
151
# config/services.yaml
@@ -239,6 +264,21 @@ Configuration of the service container then looks like this:
239
264
240
265
..configuration-block ::
241
266
267
+ ..code-block ::php-attributes
268
+
269
+ // src/Email/NewsletterManager.php
270
+ namespace App\Email;
271
+
272
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
273
+
274
+ // it's necessary to create a service for the factory
275
+ // use the factory service as the first argument of the 'factory'
276
+ // option and the factory method as the second argument
277
+ #[Autoconfigure(factory: ['@App\Email\NewsletterManagerFactory', 'createNewsletterManager'])]
278
+ class NewsletterManager
279
+ {
280
+ }
281
+
242
282
..code-block ::yaml
243
283
244
284
# config/services.yaml
@@ -325,6 +365,18 @@ method name:
325
365
326
366
..configuration-block ::
327
367
368
+ ..code-block ::php-attributes
369
+
370
+ // src/Email/NewsletterManager.php
371
+ namespace App\Email;
372
+
373
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
374
+
375
+ #[Autoconfigure(factory: '@App\Email\InvokableNewsletterManagerFactory')]
376
+ class NewsletterManager
377
+ {
378
+ }
379
+
328
380
..code-block ::yaml
329
381
330
382
# config/services.yaml
@@ -378,6 +430,20 @@ e.g. change the service based on a parameter:
378
430
379
431
..configuration-block ::
380
432
433
+ ..code-block ::php-attributes
434
+
435
+ // src/Email/NewsletterManager.php
436
+ namespace App\Email;
437
+
438
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
439
+
440
+ // use the "tracable_newsletter" service when debug is enabled, "newsletter" otherwise.
441
+ // "@=" indicates that this is an expression
442
+ #[Autoconfigure(factory: '@=parameter("kernel.debug") ? service("tracable_newsletter") : service("newsletter")')]
443
+ interface NewsletterManagerInterface
444
+ {
445
+ }
446
+
381
447
..code-block ::yaml
382
448
383
449
# config/services.yaml
@@ -457,6 +523,18 @@ previous examples takes the ``templating`` service as an argument:
457
523
458
524
..configuration-block ::
459
525
526
+ ..code-block ::php-attributes
527
+
528
+ // src/Email/NewsletterManager.php
529
+ namespace App\Email;
530
+
531
+ use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
532
+
533
+ #[Autoconfigure(bind: ['$template', '@templating'], factory: ['@App\Email\NewsletterManagerFactory', 'createNewsletterManager'])]
534
+ class NewsletterManager
535
+ {
536
+ }
537
+
460
538
..code-block ::yaml
461
539
462
540
# config/services.yaml