@@ -548,7 +548,7 @@ public function load(array $configs, ContainerBuilder $container): void
548
548
$ this ->registerProfilerConfiguration ($ config ['profiler ' ], $ container , $ loader );
549
549
550
550
if ($ this ->readConfigEnabled ('webhook ' , $ container , $ config ['webhook ' ])) {
551
- $ this ->registerWebhookConfiguration ($ config ['webhook ' ], $ container , $ loader );
551
+ $ this ->registerWebhookConfiguration ($ config ['webhook ' ], $ container , $ loader, $ this -> readConfigEnabled ( ' serializer ' , $ container , $ config [ ' serializer ' ]) );
552
552
553
553
// If Webhook is installed but the HttpClient or Serializer components are not available, we should throw an error
554
554
if (!$ this ->readConfigEnabled ('http_client ' , $ container , $ config ['http_client ' ])) {
@@ -559,14 +559,6 @@ public function load(array $configs, ContainerBuilder $container): void
559
559
)
560
560
->addTag ('container.error ' );
561
561
}
562
- if (!$ this ->readConfigEnabled ('serializer ' , $ container , $ config ['serializer ' ])) {
563
- $ container ->getDefinition ('webhook.body_configurator.json ' )
564
- ->setArguments ([])
565
- ->addError ('You cannot use the "webhook transport" service since the Serializer component is not '
566
- .(class_exists (Serializer::class) ? 'enabled. Try setting "framework.serializer.enabled" to true. ' : 'installed. Try running "composer require symfony/serializer-pack". ' )
567
- )
568
- ->addTag ('container.error ' );
569
- }
570
562
}
571
563
572
564
if ($ this ->readConfigEnabled ('remote-event ' , $ container , $ config ['remote-event ' ])) {
@@ -2919,7 +2911,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
2919
2911
}
2920
2912
}
2921
2913
2922
- private function registerWebhookConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader ): void
2914
+ private function registerWebhookConfiguration (array $ config , ContainerBuilder $ container , PhpFileLoader $ loader, bool $ serializerEnabled ): void
2923
2915
{
2924
2916
if (!class_exists (WebhookController::class)) {
2925
2917
throw new LogicException ('Webhook support cannot be enabled as the component is not installed. Try running "composer require symfony/webhook". ' );
@@ -2938,6 +2930,9 @@ private function registerWebhookConfiguration(array $config, ContainerBuilder $c
2938
2930
$ controller = $ container ->getDefinition ('webhook.controller ' );
2939
2931
$ controller ->replaceArgument (0 , $ parsers );
2940
2932
$ controller ->replaceArgument (1 , new Reference ($ config ['message_bus ' ]));
2933
+
2934
+ $ jsonBodyConfigurator = $ container ->getDefinition ('webhook.body_configurator.json ' );
2935
+ $ jsonBodyConfigurator ->replaceArgument (0 , new Reference ($ serializerEnabled ? 'webhook.payload_serializer.serializer ' : 'webhook.payload_serializer.json ' ));
2941
2936
}
2942
2937
2943
2938
private function registerRemoteEventConfiguration (PhpFileLoader $ loader ): void
0 commit comments