diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index 6852cb0108e8d..9cbd4d2285ebc 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -281,11 +281,11 @@ public function load(array $configs, ContainerBuilder $container)
// If the slugger is used but the String component is not available, we should throw an error
if (!ContainerBuilder::willBeAvailable('symfony/string', SluggerInterface::class, ['symfony/framework-bundle'])) {
- $container->register('slugger', 'stdClass')
+ $container->register('slugger', SluggerInterface::class)
->addError('You cannot use the "slugger" service since the String component is not installed. Try running "composer require symfony/string".');
} else {
if (!ContainerBuilder::willBeAvailable('symfony/translation', LocaleAwareInterface::class, ['symfony/framework-bundle'])) {
- $container->register('slugger', 'stdClass')
+ $container->register('slugger', SluggerInterface::class)
->addError('You cannot use the "slugger" service since the Translation contracts are not installed. Try running "composer require symfony/translation".');
}
@@ -379,7 +379,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->getDefinition('argument_resolver.request_payload')
->setArguments([])
->addError('You can neither use "#[MapRequestPayload]" nor "#[MapQueryString]" since the Serializer component is not '
- .(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
+ .(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer.enabled" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
)
->addTag('container.error')
->clearTag('kernel.event_subscriber');
@@ -531,6 +531,24 @@ public function load(array $configs, ContainerBuilder $container)
if ($this->readConfigEnabled('webhook', $container, $config['webhook'])) {
$this->registerWebhookConfiguration($config['webhook'], $container, $loader);
+
+ // If Webhook is installed but the HttpClient or Serializer components are not available, we should throw an error
+ if (!$this->readConfigEnabled('http_client', $container, $config['http_client'])) {
+ $container->getDefinition('webhook.transport')
+ ->setArguments([])
+ ->addError('You cannot use the "webhook transport" service since the HttpClient component is not '
+ .(class_exists(ScopingHttpClient::class) ? 'enabled. Try setting "framework.http_client.enabled" to true.' : 'installed. Try running "composer require symfony/http-client".')
+ )
+ ->addTag('container.error');
+ }
+ if (!$this->readConfigEnabled('serializer', $container, $config['serializer'])) {
+ $container->getDefinition('webhook.body_configurator.json')
+ ->setArguments([])
+ ->addError('You cannot use the "webhook transport" service since the Serializer component is not '
+ .(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer.enabled" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
+ )
+ ->addTag('container.error');
+ }
}
if ($this->readConfigEnabled('remote-event', $container, $config['remote-event'])) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook.php
new file mode 100644
index 0000000000000..5a50a738b4747
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook.php
@@ -0,0 +1,8 @@
+loadFromExtension('framework', [
+ 'http_method_override' => false,
+ 'webhook' => ['enabled' => true],
+ 'http_client' => ['enabled' => true],
+ 'serializer' => ['enabled' => true],
+]);
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook_without_serializer.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook_without_serializer.php
new file mode 100644
index 0000000000000..cd6f3ec903a24
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook_without_serializer.php
@@ -0,0 +1,8 @@
+loadFromExtension('framework', [
+ 'http_method_override' => false,
+ 'webhook' => ['enabled' => true],
+ 'http_client' => ['enabled' => true],
+ 'serializer' => ['enabled' => false],
+]);
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook.xml
new file mode 100644
index 0000000000000..aaf6952708672
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook_without_serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook_without_serializer.xml
new file mode 100644
index 0000000000000..76e72b4144bb0
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook_without_serializer.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook.yml
new file mode 100644
index 0000000000000..7c13a0fc2aa4f
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook.yml
@@ -0,0 +1,8 @@
+framework:
+ http_method_override: false
+ webhook:
+ enabled: true
+ http_client:
+ enabled: true
+ serializer:
+ enabled: true
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook_without_serializer.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook_without_serializer.yml
new file mode 100644
index 0000000000000..e61c199420451
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook_without_serializer.yml
@@ -0,0 +1,8 @@
+framework:
+ http_method_override: false
+ webhook:
+ enabled: true
+ http_client:
+ enabled: true
+ serializer:
+ enabled: false
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php
index fe3b773186218..97831b04e7773 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php
@@ -82,6 +82,8 @@
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
+use Symfony\Component\Webhook\Client\RequestParser;
+use Symfony\Component\Webhook\Controller\WebhookController;
use Symfony\Component\Workflow;
use Symfony\Component\Workflow\Exception\InvalidDefinitionException;
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
@@ -2276,6 +2278,38 @@ public function testNotifierWithSpecificMessageBus()
$this->assertEquals(new Reference('app.another_bus'), $container->getDefinition('notifier.channel.sms')->getArgument(1));
}
+ public function testWebhook()
+ {
+ if (!class_exists(WebhookController::class)) {
+ $this->markTestSkipped('Webhook not available.');
+ }
+
+ $container = $this->createContainerFromFile('webhook');
+
+ $this->assertTrue($container->hasAlias(RequestParser::class));
+ $this->assertSame('webhook.request_parser', (string) $container->getAlias(RequestParser::class));
+ $this->assertSame(RequestParser::class, $container->getDefinition('webhook.request_parser')->getClass());
+
+ $this->assertFalse($container->getDefinition('webhook.transport')->hasErrors());
+ $this->assertFalse($container->getDefinition('webhook.body_configurator.json')->hasErrors());
+ }
+
+ public function testWebhookWithoutSerializer()
+ {
+ if (!class_exists(WebhookController::class)) {
+ $this->markTestSkipped('Webhook not available.');
+ }
+
+ $container = $this->createContainerFromFile('webhook_without_serializer');
+
+ $this->assertFalse($container->getDefinition('webhook.transport')->hasErrors());
+ $this->assertTrue($container->getDefinition('webhook.body_configurator.json')->hasErrors());
+ $this->assertSame(
+ ['You cannot use the "webhook transport" service since the Serializer component is not enabled. Try setting "framework.serializer.enabled" to true.'],
+ $container->getDefinition('webhook.body_configurator.json')->getErrors()
+ );
+ }
+
protected function createContainer(array $data = [])
{
return new ContainerBuilder(new EnvPlaceholderParameterBag(array_merge([