8000 Check if serializer is enabled · symfony/symfony@84b7358 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84b7358

Browse files
committed
Check if serializer is enabled
1 parent c8e9875 commit 84b7358

File tree

8 files changed

+65
-11
lines changed

8 files changed

+65
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,25 @@ public function load(array $configs, ContainerBuilder $container)
531531

532532
if ($this->readConfigEnabled('webhook', $container, $config['webhook'])) {
533533
$this->registerWebhookConfiguration($config['webhook'], $container, $loader);
534+
535+
// If the Webhook is installed but the HttpClient or Serializer components are not available, we should throw an error
536+
if (!ContainerBuilder::willBeAvailable('symfony/http-client', HttpClientInterface::class, ['symfony/framework-bundle'])) {
537+
$container->getDefinition('webhook.transport')
538+
->setArguments([])
539+
->addError('You cannot use the "webhook transport" service since the HttpClient component is not installed. Try running "composer require symfony/http-client".')
540+
->addTag('container.error');
541+
}
542+
if (!ContainerBuilder::willBeAvailable('symfony/serializer', Serializer::class, ['symfony/framework-bundle'])) {
543+
$container->getDefinition('webhook.body_configurator.json')
544+
->setArguments([])
545+
->addError('You cannot use the "webhook transport" service since the Serializer component is not installed. Try running "composer require symfony/serializer".')
546+
->addTag('container.error');
547+
} elseif (!$this->readConfigEnabled('serializer', $container, $config['serializer'])) {
548+
$container->getDefinition('webhook.body_configurator.json')
549+
->setArguments([])
550+
->addError('The Serializer component is not enabled in your application. Enable it with the "serializer.enabled" key in "config/packages/framework.yaml".')
551+
->addTag('container.error');
552+
}
534553
}
535554

536555
if ($this->readConfigEnabled('remote-event', $container, $config['remote-event'])) {
@@ -2795,16 +2814,6 @@ private function registerWebhookConfiguration(array $config, ContainerBuilder $c
27952814

27962815
$loader->load('webhook.php');
27972816

2798-
// If the Webhook is installed but the HttpClient or Serializer components are not available, we should throw an error
2799-
if (!ContainerBuilder::willBeAvailable('symfony/http-client', HttpClientInterface::class, ['symfony/framework-bundle'])) {
2800-
$container->register('webhook.transport', 'stdClass')
2801-
->addError('You cannot use the "webhook transport" service since the HttpClient component is not installed. Try running "composer require symfony/http-client".');
2802-
}
2803-
if (!ContainerBuilder::willBeAvailable('symfony/serializer', Serializer::class, ['symfony/framework-bundle'])) {
2804-
$container->register('webhook.body_configurator.json', 'stdClass')
2805-
->addError('You cannot use the "webhook transport" service since the Serializer component is not installed. Try running "composer require symfony/serializer".');
2806-
}
2807-
28082817
$parsers = [];
28092818
foreach ($config['routing'] as $type => $cfg) {
28102819
$parsers[$type] = [

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/webhook.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
$container->loadFromExtension('framework', [
44
'http_method_override' => false,
55
'webhook' => ['enabled' => true],
6+
'serializer' => ['enabled' => true],
67
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_method_override' => false,
5+
'webhook' => ['enabled' => true],
6+
'serializer' => ['enabled' => false],
7+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/webhook.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xmlns:framework="http://symfony.com/schema/dic/symfony"
66
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7-
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config http-method-override="false">
1010
<framework:webhook enabled="true" />
11+
<framework:serializer enabled="true" />
1112
</framework:config>
1213
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config http-method-override="false">
10+
<framework:webhook enabled="true" />
11+
<framework:serializer enabled="false" />
12+
</framework:config>
13+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/webhook.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ framework:
22
http_method_override: false
33
webhook:
44
enabled: true
5+
serializer:
6+
enabled: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
framework:
2+
http_method_override: false
3+
webhook:
4+
enabled: true
5+
serializer:
6+
enabled: false

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,21 @@ public function testWebhook()
22842284
$this->assertTrue($container->hasAlias(RequestParser::class));
22852285
$this->assertSame('webhook.request_parser', (string) $container->getAlias(RequestParser::class));
22862286
$this->assertSame(RequestParser::class, $container->getDefinition('webhook.request_parser')->getClass());
2287+
2288+
$this->assertFalse($container->getDefinition('webhook.transport')->hasErrors());
2289+
$this->assertFalse($container->getDefinition('webhook.body_configurator.json')->hasErrors());
2290+
}
2291+
2292+
public function testWebhookWithoutSerializer()
2293+
{
2294+
$container = $this->createContainerFromFile('webhook_without_serializer');
2295+
2296+
$this->assertFalse($container->getDefinition('webhook.transport')->hasErrors());
2297+
$this->assertTrue($container->getDefinition('webhook.body_configurator.json')->hasErrors());
2298+
$this->assertSame(
2299+
['The Serializer component is not enabled in your application. Enable it with the "serializer.enabled" key in "config/packages/framework.yaml".'],
2300+
$container->getDefinition('webhook.body_configurator.json')->getErrors()
2301+
);
22872302
}
22882303

22892304
protected function createContainer(array $data = [])

0 commit comments

Comments
 (0)
0