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.

    # 1.
        autowire: true
        autoconfigure: true

    # 2.
            tags: ['app.email']

    # 3.
        resource: '../../src/Mailer/Email/'

    # 4.
            - !tagged_iterator app.email

    # 5.
    App\Mailer\AppMailer: ~
            #- App\Mailer\EmailCollection

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!