100100use Symfony \Component \Mailer \Bridge \Infobip \Transport \InfobipTransportFactory as InfobipMailerTransportFactory ;
101101use Symfony \Component \Mailer \Bridge \Mailchimp \Transport \MandrillTransportFactory ;
102102use Symfony \Component \Mailer \Bridge \Mailgun \Transport \MailgunTransportFactory ;
103+ use Symfony \Component \Mailer \Bridge \Mailgun \Webhook \MailgunRequestParser ;
103104use Symfony \Component \Mailer \Bridge \Mailjet \Transport \MailjetTransportFactory ;
104105use Symfony \Component \Mailer \Bridge \OhMySmtp \Transport \OhMySmtpTransportFactory ;
105106use Symfony \Component \Mailer \Bridge \Postmark \Transport \PostmarkTransportFactory ;
107+ use Symfony \Component \Mailer \Bridge \Postmark \Webhook \PostmarkRequestParser ;
106108use Symfony \Component \Mailer \Bridge \Sendgrid \Transport \SendgridTransportFactory ;
107109use Symfony \Component \Mailer \Bridge \Sendinblue \Transport \SendinblueTransportFactory ;
108110use Symfony \Component \Mailer \Command \MailerTestCommand ;
205207use Symfony \Component \RateLimiter \LimiterInterface ;
206208use Symfony \Component \RateLimiter \RateLimiterFactory ;
207209use Symfony \Component \RateLimiter \Storage \CacheStorage ;
210+ use Symfony \Component \RemoteEvent \Attribute \AsRemoteEventConsumer ;
211+ use Symfony \Component \RemoteEvent \Consumer \ConsumerInterface ;
212+ use Symfony \Component \RemoteEvent \Event ;
208213use Symfony \Component \Routing \Loader \Psr4DirectoryLoader ;
209214use Symfony \Component \Security \Core \AuthenticationEvents ;
210215use Symfony \Component \Security \Core \Exception \AuthenticationException ;
239244use Symfony \Component \Validator \Mapping \Loader \PropertyInfoLoader ;
240245use Symfony \Component \Validator \ObjectInitializerInterface ;
241246use Symfony \Component \Validator \Validation ;
247+ use Symfony \Component \Webhook \Controller \WebhookController ;
242248use Symfony \Component \WebLink \HttpHeaderSerializer ;
243249use Symfony \Component \Workflow ;
244250use Symfony \Component \Workflow \WorkflowInterface ;
@@ -396,7 +402,7 @@ public function load(array $configs, ContainerBuilder $container)
396402 }
397403
398404 if ($ this ->readConfigEnabled ('mailer ' , $ container , $ config ['mailer ' ])) {
399- $ this ->registerMailerConfiguration ($ config ['mailer ' ], $ container , $ loader );
405+ $ this ->registerMailerConfiguration ($ config ['mailer ' ], $ container , $ loader, $ this -> readConfigEnabled ( ' webhook ' , $ container , $ config [ ' webhook ' ]) );
400406
401407 if (!$ this ->hasConsole () || !class_exists (MailerTestCommand::class)) {
402408 $ container ->removeDefinition ('console.command.mailer_test ' );
@@ -551,12 +557,20 @@ public function load(array $configs, ContainerBuilder $container)
551557
552558 // notifier depends on messenger, mailer being registered
553559 if ($ this ->readConfigEnabled ('notifier ' , $ container , $ config ['notifier ' ])) {
554- $ this ->registerNotifierConfiguration ($ config ['notifier ' ], $ container , $ loader );
560+ $ this ->registerNotifierConfiguration ($ config ['notifier ' ], $ container , $ loader, $ this -> readConfigEnabled ( ' webhook ' , $ container , $ config [ ' webhook ' ]) );
555561 }
556562
557563 // profiler depends on form, validation, translation, messenger, mailer, http-client, notifier, serializer being registered
558564 $ this ->registerProfilerConfiguration ($ config ['profiler ' ], $ container , $ loader );
559565
566+ if ($ this ->readConfigEnabled ('webhook ' , $ container , $ config ['webhook ' ])) {
567+ $ this ->registerWebhookConfiguration ($ config ['webhook ' ], $ container , $ loader );
568+ }
569+
570+ if ($ this ->readConfigEnabled ('remote-event ' , $ container , $ config ['remote-event ' ])) {
571+ $ this ->registerRemoteEventConfiguration ($ config ['remote-event ' ], $ container , $ loader );
572+ }
573+
560574 if ($ this ->readConfigEnabled ('html_sanitizer ' , $ container , $ config ['html_sanitizer ' ])) {
561575 if (!class_exists (HtmlSanitizerConfig::class)) {
562576 throw new LogicException ('HtmlSanitizer support cannot be enabled as the HtmlSanitizer component is not installed. Try running "composer require symfony/html-sanitizer". ' );
@@ -655,6 +669,8 @@ public function load(array $configs, ContainerBuilder $container)
655669 ->addTag ('messenger.transport_factory ' );
656670 $ container ->registerForAutoconfiguration (MimeTypeGuesserInterface::class)
657671 ->addTag ('mime.mime_type_guesser ' );
672+ $ container ->registerForAutoconfiguration (ConsumerInterface::class)
673+ ->addTag ('remote_event.consumer ' );
658674 $ container ->registerForAutoconfiguration (LoggerAwareInterface::class)
659675 ->addMethodCall ('setLogger ' , [new Reference ('logger ' )]);
660676
@@ -671,7 +687,9 @@ public function load(array $configs, ContainerBuilder $container)
671687 $ container ->registerAttributeForAutoconfiguration (AsController::class, static function (ChildDefinition $ definition , AsController $ attribute ): void {
672688 $ definition ->addTag ('controller.service_arguments ' );
673689 });
674-
690+ $ container ->registerAttributeForAutoconfiguration (AsRemoteEventConsumer::class, static function (ChildDefinition $ definition , AsRemoteEventConsumer $ attribute ): void {
691+ $ definition ->addTag ('remote_event.consumer ' , ['consumer ' => $ attribute ->name ]);
692+ });
675693 $ container ->registerAttributeForAutoconfiguration (AsMessageHandler::class, static function (ChildDefinition $ definition , AsMessageHandler $ attribute , \ReflectionClass |\ReflectionMethod $ reflector ): void {
676694 $ tagAttributes = get_object_vars ($ attribute );
677695 $ tagAttributes ['from_transport ' ] = $ tagAttributes ['fromTransport ' ];
@@ -2436,7 +2454,7 @@ private function registerRetryableHttpClient(array $options, string $name, Conta
24362454 ->addTag ('monolog.logger ' , ['channel ' => 'http_client ' ]);
24372455 }
24382456
2439- private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2457+ private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled )
24402458 {
24412459 if (!class_exists (Mailer::class)) {
24422460 throw new LogicException ('Mailer support cannot be enabled as the component is not installed. Try running "composer require symfony/mailer". ' );
@@ -2479,6 +2497,19 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
24792497 }
24802498 }
24812499
2500+ $ webhookRequestParsers = [
2501+ MailgunRequestParser::class => 'mailer.webhook_request_parser.mailgun ' ,
2502+ PostmarkRequestParser::class => 'mailer.webhook_request_parser.postmark ' ,
2503+ ];
2504+
2505+ foreach ($ webhookRequestParsers as $ class => $ service ) {
2506+ $ package = substr ($ service , \strlen ('mailer.transport_factory. ' ));
2507+
2508+ if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-mailer ' , 'gmail ' === $ package ? 'google ' : $ package ), $ class , ['symfony/framework-bundle ' , 'symfony/mailer ' ])) {
2509+ $ container ->removeDefinition ($ service );
2510+ }
2511+ }
2512+
24822513 $ envelopeListener = $ container ->getDefinition ('mailer.envelope_listener ' );
24832514 $ envelopeListener ->setArgument (0 , $ config ['envelope ' ]['sender ' ] ?? null );
24842515 $ envelopeListener ->setArgument (1 , $ config ['envelope ' ]['recipients ' ] ?? null );
@@ -2501,9 +2532,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
25012532 if (!class_exists (MessengerTransportListener::class)) {
25022533 $ container ->removeDefinition ('mailer.messenger_transport_listener ' );
25032534 }
2535+
2536+ if ($ webhookEnabled && class_exists (Event::class)) {
2537+ $ loader ->load ('mailer_webhook.php ' );
2538+ }
25042539 }
25052540
2506- private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2541+ private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled )
25072542 {
25082543 if (!class_exists (Notifier::class)) {
25092544 throw new LogicException ('Notifier support cannot be enabled as the component is not installed. Try running "composer require symfony/notifier". ' );
@@ -2654,6 +2689,38 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
26542689 $ notifier ->addMethodCall ('addAdminRecipient ' , [new Reference ($ id )]);
26552690 }
26562691 }
2692+
2693+ if ($ webhookEnabled && class_exists (Event::class)) {
2694+ $ loader ->load ('notifier_webhook.php ' );
2695+ }
2696+ }
2697+
2698+ private function registerWebhookConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2699+ {
2700+ if (!class_exists (WebhookController::class)) {
2701+ throw new LogicException ('Webhook support cannot be enabled as the component is not installed. Try running "composer require symfony/webhook". ' );
2702+ }
2703+
2704+ $ loader ->load ('webhook.php ' );
2705+
2706+ $ parsers = [];
2707+ foreach ($ config ['routing ' ] as $ type => $ config ) {
2708+ // FIXME: xml config in the schema to be fixed
2709+ $ parsers [$ type ] = [
2710+ 'parser ' => $ container ->findDefinition ($ config ['service ' ]),
2711+ 'secret ' => $ config ['secret ' ]
2712+ ];
2713+ }
2714+ $ container ->getDefinition (WebhookController::class)->replaceArgument (0 , $ parsers );
2715+ }
2716+
2717+ private function registerRemoteEventConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2718+ {
2719+ if (!class_exists (Event::class)) {
2720+ throw new LogicException ('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event". ' );
2721+ }
2722+
2723+ $ loader ->load ('remote_event.php ' );
26572724 }
26582725
26592726 private function registerRateLimiterConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
0 commit comments