symfony - @mailer and @twig in argument of a service error ServiceCircularReferenceException -
i'm trying put twig argument of service have same error :
servicecircularreferenceexception in bootstrap.php.cache line 2129
circular reference detected service "doctrine.orm.default_entity_manager",path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> wh.participant_listener -> wh.participant_notification -> twig -> security.authorization_checker -> security.authentication.manager -> fos_user.user_provider.username -> fos_user.user_manager".`
this service.yml file
wh.participant_notification: class: wh\trainingbundle\notification\notification arguments: [@mailer, @twig] wh.participant_listener: class: wh\trainingbundle\eventlistener\participantlistener arguments: [@wh.participant_notification] tags: - { name: doctrine.event_listener, event: postupdate } - { name: doctrine.event_listener, event: postpersist }
my partcicipantlistenerfile
namespace wh\trainingbundle\eventlistener; use doctrine\orm\event\lifecycleeventargs; use wh\trainingbundle\notification\notification; class participantlistener { protected $notification; public function __construct(notification $notification) { $this->notification = $notification; } }
this probleme exist when pass @wh.participant_notificationin arguments of second service
any body has idea ?
thank's lot
i've find solution, not pretty, works :
first pass service container in argument of service
services: wh.participant_notification: class: wh\trainingbundle\notification\notification arguments: ['@service_container'] wh.participant_listener: class: wh\trainingbundle\eventlistener\participantlistener arguments: ['@wh.participant_notification'] tags: - { name: doctrine.event_listener, event: postpersist }
then in notification.php class :
use symfony\component\dependencyinjection\containerinterface container; private $container; public function __construct(container $container) { $this->container = $container; } public function subscribvalidation ($participant) { $templating = $this->container->get('templating'); $mailer = $this->container->get('mailer'); ...
i can't create protected var $twig because probleme persiste. repeat, twig service (or template). maybe 1 find better solution ...
Comments
Post a Comment