S
S
symnoob2021-05-27 14:48:41
symfony
symnoob, 2021-05-27 14:48:41

Is it possible to somehow tag services through the implements interface?

Hello everyone,

at the moment I'm tagging services, like this:

services.yaml:

MyNamespace\Service\MyService:
  autowire: true
  tags:
    - {name: app.my_tag}


Is it possible to do this somehow when creating a class (Service)?

For example:
class MyClass implements MyInterfaceForTagging{
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2021-05-27
@symnoob

Yes, starting from version 3.3, examples are in the documentation . In your case it will be:

# app/config/services.yml
services:
    _instanceof:
        MyNamespace\Service\MyInterfaceForTagging:
            tags: ['app.my_tag']

Also, starting with version 5.3, which will be released one of these days, it will be possible to use attributes from PHP8 for the same purpose, blog article about this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question