ZeSoft
ZeSoft

Reputation: 335

calling twigswiftmailer inside Guard Authenticator in symfony 2

i am using guard as my custom authenticator, i need to send an email inside the authenticator, using the service fos_user.mailer that i injected which has arguments amoung which there is twig because it renders the message it needs to send, now the problem i have is that i get an error "Circular reference detected for service ..." which says that my authenticator calls the mailer which calls the twig which again calls the authorization checker (my authenticator) resulting in an endless loop, do you have any solutions for this

Upvotes: -1

Views: 59

Answers (1)

Maerlyn
Maerlyn

Reputation: 34107

The quick and dirty workaround is to inject the container to your authenticator and get the mailer service when you need it. It's dirty, because it hides your dependencies.

But why do you need to send an email in your authenticator? Can you use one of symfony's authentication-related events instead? (See the AuthenticationEvents and SecurityEvents classes). If that's not enough, you can also create your own event and listen to that in a different service, that's responsible for sending that mail.

Upvotes: 0

Related Questions