102
102
use Symfony \Component \Mailer \Bridge \Mailchimp \Transport \MandrillTransportFactory ;
103
103
use Symfony \Component \Mailer \Bridge \MailerSend \Transport \MailerSendTransportFactory ;
104
104
use Symfony \Component \Mailer \Bridge \Mailgun \Transport \MailgunTransportFactory ;
105
+ use Symfony \Component \Mailer \Bridge \Mailgun \Webhook \MailgunRequestParser ;
105
106
use Symfony \Component \Mailer \Bridge \Mailjet \Transport \MailjetTransportFactory ;
106
107
use Symfony \Component \Mailer \Bridge \MailPace \Transport \MailPaceTransportFactory ;
107
108
use Symfony \Component \Mailer \Bridge \OhMySmtp \Transport \OhMySmtpTransportFactory ;
108
109
use Symfony \Component \Mailer \Bridge \Postmark \Transport \PostmarkTransportFactory ;
110
+ use Symfony \Component \Mailer \Bridge \Postmark \Webhook \PostmarkRequestParser ;
109
111
use Symfony \Component \Mailer \Bridge \Sendgrid \Transport \SendgridTransportFactory ;
110
112
use Symfony \Component \Mailer \Bridge \Sendinblue \Transport \SendinblueTransportFactory ;
111
113
use Symfony \Component \Mailer \Command \MailerTestCommand ;
210
212
use Symfony \Component \RateLimiter \LimiterInterface ;
211
213
use Symfony \Component \RateLimiter \RateLimiterFactory ;
212
214
use Symfony \Component \RateLimiter \Storage \CacheStorage ;
215
+ use Symfony \Component \RemoteEvent \Attribute \AsRemoteEventConsumer ;
216
+ use Symfony \Component \RemoteEvent \RemoteEvent ;
213
217
use Symfony \Component \Routing \Loader \Psr4DirectoryLoader ;
214
218
use Symfony \Component \Security \Core \AuthenticationEvents ;
215
219
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
244
248
use Symfony \Component \Validator \Mapping \Loader \PropertyInfoLoader ;
245
249
use Symfony \Component \Validator \ObjectInitializerInterface ;
246
250
use Symfony \Component \Validator \Validation ;
251
+ use Symfony \Component \Webhook \Controller \WebhookController ;
247
252
use Symfony \Component \WebLink \HttpHeaderSerializer ;
248
253
use Symfony \Component \Workflow ;
249
254
use Symfony \Component \Workflow \WorkflowInterface ;
@@ -403,7 +408,7 @@ public function load(array $configs, ContainerBuilder $container)
403
408
}
404
409
405
410
if ($ this ->readConfigEnabled ('mailer ' , $ container , $ config ['mailer ' ])) {
406
- $ this ->registerMailerConfiguration ($ config ['mailer ' ], $ container , $ loader );
411
+ $ this ->registerMailerConfiguration ($ config ['mailer ' ], $ container , $ loader, $ this -> readConfigEnabled ( ' webhook ' , $ container , $ config [ ' webhook ' ]) );
407
412
408
413
if (!$ this ->hasConsole () || !class_exists (MailerTestCommand::class)) {
409
414
$ container ->removeDefinition ('console.command.mailer_test ' );
@@ -558,12 +563,20 @@ public function load(array $configs, ContainerBuilder $container)
558
563
559
564
// notifier depends on messenger, mailer being registered
560
565
if ($ this ->readConfigEnabled ('notifier ' , $ container , $ config ['notifier ' ])) {
561
- $ this ->registerNotifierConfiguration ($ config ['notifier ' ], $ container , $ loader );
566
+ $ this ->registerNotifierConfiguration ($ config ['notifier ' ], $ container , $ loader, $ this -> readConfigEnabled ( ' webhook ' , $ container , $ config [ ' webhook ' ]) );
562
567
}
563
568
564
569
// profiler depends on form, validation, translation, messenger, mailer, http-client, notifier, serializer being registered
565
570
$ this ->registerProfilerConfiguration ($ config ['profiler ' ], $ container , $ loader );
566
571
572
+ if ($ this ->readConfigEnabled ('webhook ' , $ container , $ config ['webhook ' ])) {
573
+ $ this ->registerWebhookConfiguration ($ config ['webhook ' ], $ container , $ loader );
574
+ }
575
+
576
+ if ($ this ->readConfigEnabled ('remote-event ' , $ container , $ config ['remote-event ' ])) {
577
+ $ this ->registerRemoteEventConfiguration ($ config ['remote-event ' ], $ container , $ loader );
578
+ }
579
+
567
580
if ($ this ->readConfigEnabled ('html_sanitizer ' , $ container , $ config ['html_sanitizer ' ])) {
568
581
if (!class_exists (HtmlSanitizerConfig::class)) {
569
582
throw new LogicException ('HtmlSanitizer support cannot be enabled as the HtmlSanitizer component is not installed. Try running "composer require symfony/html-sanitizer". ' );
@@ -678,7 +691,9 @@ public function load(array $configs, ContainerBuilder $container)
678
691
$ container ->registerAttributeForAutoconfiguration (AsController::class, static function (ChildDefinition $ definition , AsController $ attribute ): void {
679
692
$ definition ->addTag ('controller.service_arguments ' );
680
693
});
681
-
694
+ $ container ->registerAttributeForAutoconfiguration (AsRemoteEventConsumer::class, static function (ChildDefinition $ definition , AsRemoteEventConsumer $ attribute ): void {
695
+ $ definition ->addTag ('remote_event.consumer ' , ['consumer ' => $ attribute ->name ]);
696
+ });
682
697
$ container ->registerAttributeForAutoconfiguration (AsMessageHandler::class, static function (ChildDefinition $ definition , AsMessageHandler $ attribute , \ReflectionClass |\ReflectionMethod $ reflector ): void {
683
698
$ tagAttributes = get_object_vars ($ attri
10000
bute );
684
699
$ tagAttributes ['from_transport ' ] = $ tagAttributes ['fromTransport ' ];
@@ -2467,7 +2482,7 @@ private function registerRetryableHttpClient(array $options, string $name, Conta
2467
2482
->addTag ('monolog.logger ' , ['channel ' => 'http_client ' ]);
2468
2483
}
2469
2484
2470
- private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader ): void
2485
+ private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled ): void
2471
2486
{
2472
2487
if (!class_exists (Mailer::class)) {
2473
2488
throw new LogicException ('Mailer support cannot be enabled as the component is not installed. Try running "composer require symfony/mailer". ' );
@@ -2512,6 +2527,19 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
2512
2527
}
2513
2528
}
2514
2529
2530
+ $ webhookRequestParsers = [
2531
+ MailgunRequestParser::class => 'mailer.webhook.request_parser.mailgun ' ,
2532
+ PostmarkRequestParser::class => 'mailer.webhook.request_parser.postmark ' ,
2533
+ ];
2534
+
2535
+ foreach ($ webhookRequestParsers as $ class => $ service ) {
2536
+ $ package = substr ($ service , \strlen ('mailer.transport_factory. ' ));
2537
+
2538
+ if (!ContainerBuilder::willBeAvailable (sprintf ('symfony/%s-mailer ' , 'gmail ' === $ package ? 'google ' : $ package ), $ class , ['symfony/framework-bundle ' , 'symfony/mailer ' ])) {
2539
+ $ container ->removeDefinition ($ service );
2540
+ }
2541
+ }
2542
+
2515
2543
$ envelopeListener = $ container ->getDefinition ('mailer.envelope_listener ' );
2516
2544
$ envelopeListener ->setArgument (0 , $ config ['envelope ' ]['sender ' ] ?? null );
2517
2545
$ envelopeListener ->setArgument (1 , $ config ['envelope ' ]['recipients ' ] ?? null );
@@ -2534,9 +2562,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
2534
2562
if (!class_exists (MessengerTransportListener::class)) {
2535
2563
$ container ->removeDefinition ('mailer.messenger_transport_listener ' );
2536
2564
}
2565
+
2566
+ if ($ webhookEnabled ) {
2567
+ $ loader ->load ('mailer_webhook.php ' );
2568
+ }
2537
2569
}
2538
2570
2539
- private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader ): void
2571
+ private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled ): void
2540
2572
{
2541
2573
if (!class_exists (Notifier::class)) {
2542
2574
throw new LogicException ('Notifier support cannot be enabled as the component is not installed. Try running "composer require symfony/notifier". ' );
@@ -2701,6 +2733,40 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
2701
2733
$ notifier ->addMethodCall ('addAdminRecipient ' , [new Reference ($ id )]);
2702
2734
}
2703
2735
}
2736
+
2737
+ if ($ webhookEnabled ) {
2738
+ $ loader ->load ('notifier_webhook.php ' );
2739
+ }
2740
+ }
2741
+
2742
+ private function registerWebhookConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2743
+ {
2744
+ if (!class_exists (WebhookController::class)) {
2745
+ throw new LogicException ('Webhook support cannot be enabled as the component is not installed. Try running "composer require symfony/webhook". ' );
2746
+ }
2747
+
2748
+ $ loader ->load ('webhook.php ' );
2749
+
2750
+ $ parsers = [];
2751
+ foreach ($ config ['routing ' ] as $ type => $ cfg ) {
2752
+ $ parsers [$ type ] = [
2753
+ 'parser ' => new Reference ($ cfg ['service ' ]),
2754
+ 'secret ' => $ cfg ['secret ' ],
2755
+ ];
2756
+ }
2757
+
2758
+ $ controller = $ container ->getDefinition ('webhook.controller ' );
2759
+ $ controller ->replaceArgument (0 , $ parsers );
2760
+ $ controller ->replaceArgument (1 , new Reference ($ config ['message_bus ' ]));
2761
+ }
2762
+
2763
+ private function registerRemoteEventConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2764
+ {
2765
+ if (!class_exists (RemoteEvent::class)) {
2766
+ throw new LogicException ('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event". ' );
2767
+ }
2768
+
2769
+ $ loader ->load ('remote_event.php ' );
2704
2770
}
2705
2771
2706
2772
private function registerRateLimiterConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader ): void
0 commit comments