Skip to content
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

#[AsMessageHandler] on abstract classes produces untagged services #655

Open
possi opened this issue Aug 2, 2024 · 0 comments
Open

#[AsMessageHandler] on abstract classes produces untagged services #655

possi opened this issue Aug 2, 2024 · 0 comments

Comments

@possi
Copy link

possi commented Aug 2, 2024

Example:

abstract class AbstractHandler implements MessageHandlerInterface {

}
class ExampleHandler extends AbstractHandler {
  // ...
}

Thanks to symfony-frameworks registerForAutoconfiguration the ExampleHandler is tagged as messenger.message_handler, as the class (indirect) implements the interface.


Result after rector:

#[AsMessageHandler]
abstract class AbstractHandler {
  // ...
}
class ExampleHandler extends AbstractHandler {
  // ...
}

No service gets tagged:

  • abstract classes aren't considered a service, and therefore no tagging is happening
  • the ExampleHandler has no attribute to it and doesn't get the tag added.

Possible solution:

I would recommend to add final to all modified classes. This prevents extending a message handler service and expecting to automaticly get tagged. Any wrong usages are instantly visible.
Just skipping abstract classes wouldn't be sufficient, as some may also extend a non abstract service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant