YAML template to create a Symfony tagged iterator service
Published on 2023-01-06 • Modified on 2023-01-06
This snippet shows a YAML template to create a Symfony tagged iterator service:
1. We activate autowiring and autoconfigure.
2. We declare to assign the app.email
tag to all services implementing the EmailInterface
.
3. We load all services implementing the EmailInterface
in a given directory.
4. We inject all the tagged services app.email
into the EmailCollection
service.
5. Then, we can use the EmailCollection
service in other services thanks to autowiring.
services:
# 1.
_defaults:
autowire: true
autoconfigure: true
# 2.
_instanceof:
App\Mailer\Email\EmailInterface:
tags: ['app.email']
# 3.
App\Mailer\Email\:
resource: '../../src/Mailer/Email/'
# 4.
App\Mailer\EmailCollection:
arguments:
- !tagged_iterator app.email
# 5.
App\Mailer\AppMailer: ~
#arguments:
#- App\Mailer\EmailCollection
More on Stackoverflow Read the doc Random snippet
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉
