100
100
use Symfony \Component \Mailer \Bridge \Infobip \Transport \InfobipTransportFactory as InfobipMailerTransportFactory ;
101
101
use Symfony \Component \Mailer \Bridge \Mailchimp \Transport \MandrillTransportFactory ;
102
102
use Symfony \Component \Mailer \Bridge \Mailgun \Transport \MailgunTransportFactory ;
103
+ use Symfony \Component \Mailer \Bridge \Mailgun \Webhook \MailgunRequestParser ;
103
104
use Symfony \Component \Mailer \Bridge \Mailjet \Transport \MailjetTransportFactory ;
104
105
use Symfony \Component \Mailer \Bridge \OhMySmtp \Transport \OhMySmtpTransportFactory ;
105
106
use Symfony \Component \Mailer \Bridge \Postmark \Transport \PostmarkTransportFactory ;
107
+ use Symfony \Component \Mailer \Bridge \Postmark \Webhook \PostmarkRequestParser ;
106
108
use Symfony \Component \Mailer \Bridge \Sendgrid \Transport \SendgridTransportFactory ;
107
109
use Symfony \Component \Mailer \Bridge \Sendinblue \Transport \SendinblueTransportFactory ;
108
110
use Symfony \Component \Mailer \Command \MailerTestCommand ;
205
207
use Symfony \Component \RateLimiter \LimiterInterface ;
206
208
use Symfony \Component \RateLimiter \RateLimiterFactory ;
207
209
use 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 ;
208
213
use Symfony \Component \Routing \Loader \Psr4DirectoryLoader ;
209
214
use Symfony \Component \Security \Core \AuthenticationEvents ;
210
215
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
239
244
use Symfony \Component \Validator \Mapping \Loader \PropertyInfoLoader ;
240
245
use Symfony \Component \Validator \ObjectInitializerInterface ;
241
246
use Symfony \Component \Validator \Validation ;
247
+ use Symfony \Component \Webhook \Controller \WebhookController ;
242
248
use Symfony \Component \WebLink \HttpHeaderSerializer ;
243
249
use Symfony \Component \Workflow ;
244
250
use Symfony \Component \Workflow \WorkflowInterface ;
@@ -396,7 +402,7 @@ public function load(array $configs, ContainerBuilder $container)
396
402
}
397
403
398
404
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 ' ]) );
400
406
401
407
if (!$ this ->hasConsole () || !class_exists (MailerTestCommand::class)) {
402
408
$ container ->removeDefinition ('console.command.mailer_test ' );
@@ -551,12 +557,20 @@ public function load(array $configs, ContainerBuilder $container)
551
557
552
558
// notifier depends on messenger, mailer being registered
553
559
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 ' ]) );
555
561
}
556
562
557
563
// profiler depends on form, validation, translation, messenger, mailer, http-client, notifier, serializer being registered
558
564
$ this ->registerProfilerConfiguration ($ config ['profiler ' ], $ container , $ loader );
559
565
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
+
560
574
if ($ this ->readConfigEnabled ('html_sanitizer ' , $ container , $ config ['html_sanitizer ' ])) {
561
575
if (!class_exists (HtmlSanitizerConfig::class)) {
562
576
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)
655
669
->addTag ('messenger.transport_factory ' );
656
670
$ container ->registerForAutoconfiguration (MimeTypeGuesserInterface::class)
657
671
->addTag ('mime.mime_type_guesser ' );
672
+ $ container ->registerForAutoconfiguration (ConsumerInterface::class)
673
+ ->addTag ('remote_event.consumer ' );
658
674
$ container ->registerForAutoconfiguration (LoggerAwareInterface::class)
659
675
->addMethodCall ('setLogger ' , [new Reference ('logger ' )]);
660
676
@@ -671,7 +687,9 @@ public function load(array $configs, ContainerBuilder $container)
671
687
$ container ->registerAttributeForAutoconfiguration (AsController::class, static function (ChildDefinition $ definition , AsController $ attribute ): void {
672
688
$ definition ->addTag ('controller.service_arguments ' );
673
689
});
674
-
690
+ $ container ->registerAttributeForAutoconfiguration (AsRemoteEventConsumer::class, static function (ChildDefinition $ definition , AsRemoteEventConsumer $ attribute ): void {
691
+ $ definition ->addTag ('remote_event.consumer ' , ['consumer ' => $ attribute ->name ]);
692
+ });
675
693
$ container ->registerAttributeForAutoconfiguration (AsMessageHandler::class, static function (ChildDefinition $ definition , AsMessageHandler $ attribute , \ReflectionClass |\ReflectionMethod $ reflector ): void {
676
694
$ tagAttributes = get_object_vars ($ attribute );
677
695
$ tagAttributes ['from_transport ' ] = $ tagAttributes ['fromTransport ' ];
@@ -2436,7 +2454,7 @@ private function registerRetryableHttpClient(array $options, string $name, Conta
2436
2454
->addTag ('monolog.logger ' , ['channel ' => 'http_client ' ]);
2437
2455
}
2438
2456
2439
- private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2457
+ private function registerMailerConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled )
2440
2458
{
2441
2459
if (!class_exists (Mailer::class)) {
2442
2460
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
2479
2497
}
2480
2498
}
2481
2499
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
+
2482
2513
$ envelopeListener = $ container ->getDefinition ('mailer.envelope_listener ' );
2483
2514
$ envelopeListener ->setArgument (0 , $ config ['envelope ' ]['sender ' ] ?? null );
2484
2515
$ envelopeListener ->setArgument (1 , $ config ['envelope ' ]['recipients ' ] ?? null );
@@ -2501,9 +2532,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
2501
2532
if (!class_exists (MessengerTransportListener::class)) {
2502
2533
$ container ->removeDefinition ('mailer.messenger_transport_listener ' );
2503
2534
}
2535
+
2536
+ if ($ webhookEnabled && class_exists (Event::class)) {
2537
+ $ loader ->load ('mailer_webhook.php ' );
2538
+ }
2504
2539
}
2505
2540
2506
- private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
2541
+ private function registerNotifierConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ webhookEnabled )
2507
2542
{
2508
2543
if (!class_exists (Notifier::class)) {
2509
2544
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 $
2654
2689
$ notifier ->addMethodCall ('addAdminRecipient ' , [new Reference ($ id )]);
2655
2690
}
2656
2691
}
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 ' );
2657
2724
}
2658
2725
2659
2726
private function registerRateLimiterConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader )
0 commit comments