-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Use classes for container tags #37194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see a big drawback to your proposal: currently, it is perfectly fine to define services that hook into extensions points of other bundles (through a tag), without checking first whether the bundle is enabled (which is a pain if you care about it being enabled, and not just installed, even without counting the extra pain when using non-PHP files). That works fine, as Symfony will remove this private service which is unused when the bundle is not there. But if you use a tag builder object from the bundle itself, your config file now has a strong dependency to that bundle. And I also fear that it might push bundles to implement some logic in their |
Having the I like the idea; however, it introduces some serious problems. The absence of strict checking is quite useful here as it allows us to specify metadata that may or may not be used (as @stof explained), or to add custom metadata to existing tags that are used by a custom compiler pass. On the other hand, if we can deal with these usecases, then it would be a great improvement. |
getAttributes is only called internally when adding the tag. what would custom getters do? this is only about the external way to add tags. internally, e.g. in compiler passes, things would stay the same. otherwise we would need to deprecate using strings/arrays as name/attribute completely. that would be an extra step that is probably not worth it.
just use a separate tag for this |
@stof has a point. Declarative statements don't play very well with classes which all need implementations (the same will be true with php8's attributes btw.) |
Thank you for this suggestion. |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
Currently tags are just strings and the attributes are arrays whose values depend on the tag. See for example
symfony/src/Symfony/Bundle/TwigBundle/Resources/config/twig.php
Lines 95 to 97 in 9b08626
I propose to allow define tags as classes which just need to implement an interface like
Then we can allow tags to be instances of the interface and can create classes that represent the tags , e.g.
->tag((new DataCollectorTag)->template('...')->id('twig')->priority(257))
. This makes tags discovorable, autocomplete, supporting types, documentable in code and validatable.The main objective with the move to use PHP to define services (#36778) is discovorability and auto-completion. With tags as classes this would also improve the situation for tags as people can easiliy find the available tags as the classes implement this interface and the attributes for each tag allow auto-completion.
Before using php for service definitions, tags as classes wasn't really an option in YAML/XML. But now I think it's time to do that transition for the php configuration format. This is also more in-line with similar concepts like the Messenger stamps that are classes as well.
A previous proposal to use constants for tags (#24377) did not solve the problem for attributes and also does not improve discovorability much as it highly depends on where you define the constants.
The text was updated successfully, but these errors were encountered: