Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2535c8c

Browse files
committed
-
1 parent 772a24c commit 2535c8c

File tree

16 files changed

+69
-37
lines changed

16 files changed

+69
-37
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,7 @@ private function addWebhookSection(ArrayNodeDefinition $rootNode, callable $enab
20822082
->info('Webhook configuration')
20832083
->{$enableIfStandalone('symfony/webhook', WebhookController::class)}()
20842084
->children()
2085+
->scalarNode('message_bus')->defaultValue('messenger.default_bus')->info('The message bus to use.')->end()
20852086
->arrayNode('routing')
20862087
->normalizeKeys(false)
20872088
->useAttributeAsKey('type')

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@
213213
use Symfony\Component\RateLimiter\RateLimiterFactory;
214214
use Symfony\Component\RateLimiter\Storage\CacheStorage;
215215
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
216-
use Symfony\Component\RemoteEvent\Consumer\ConsumerInterface;
217216
use Symfony\Component\RemoteEvent\RemoteEvent;
218217
use Symfony\Component\Routing\Loader\Psr4DirectoryLoader;
219218
use Symfony\Component\Security\Core\AuthenticationEvents;
@@ -676,8 +675,6 @@ public function load(array $configs, ContainerBuilder $container)
676675
->addTag('messenger.transport_factory');
677676
$container->registerForAutoconfiguration(MimeTypeGuesserInterface::class)
678677
->addTag('mime.mime_type_guesser');
679-
$container->registerForAutoconfiguration(ConsumerInterface::class)
680-
->addTag('remote_event.consumer');
681678
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
682679
->addMethodCall('setLogger', [new Reference('logger')]);
683680

@@ -2531,8 +2528,8 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
25312528
}
25322529

25332530
$webhookRequestParsers = [
2534-
MailgunRequestParser::class => 'mailer.webhook_request_parser.mailgun',
2535-
PostmarkRequestParser::class => 'mailer.webhook_request_parser.postmark',
2531+
MailgunRequestParser::class => 'mailer.webhook.request_parser.mailgun',
2532+
PostmarkRequestParser::class => 'mailer.webhook.request_parser.postmark',
25362533
];
25372534

25382535
foreach ($webhookRequestParsers as $class => $service) {
@@ -2751,14 +2748,16 @@ private function registerWebhookConfiguration(array $config, ContainerBuilder $c
27512748
$loader->load('webhook.php');
27522749

27532750
$parsers = [];
2754-
foreach ($config['routing'] as $type => $config) {
2755-
// FIXME: xml config in the schema to be fixed
2751+
foreach ($config['routing'] as $type => $cfg) {
27562752
$parsers[$type] = [
2757-
'parser' => $container->findDefinition($config['service']),
2758-
'secret' => $config['secret'],
2753+
'parser' => new Reference($cfg['service']),
2754+
'secret' => $cfg['secret'],
27592755
];
27602756
}
2761-
$container->getDefinition(WebhookController::class)->replaceArgument(0, $parsers);
2757+
2758+
$controller = $container->getDefinition('webhook.controller');
2759+
$controller->replaceArgument(0, $parsers);
2760+
$controller->replaceArgument(1, new Reference($config['message_bus']));
27622761
}
27632762

27642763
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_webhook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
return static function (ContainerConfigurator $container) {
2020
$container->services()
2121
->set('mailer.payload_converter.mailgun', MailgunPayloadConverter::class)
22-
->set('mailer.webhook_request_parser.mailgun', MailgunRequestParser::class)
22+
->set('mailer.webhook.request_parser.mailgun', MailgunRequestParser::class)
2323
->args([service('mailer.payload_converter.mailgun')])
24-
->alias(MailgunRequestParser::class, 'mailer.webhook_request_parser.mailgun')
24+
->alias(MailgunRequestParser::class, 'mailer.webhook.request_parser.mailgun')
2525

2626
->set('mailer.payload_converter.postmark', PostmarkPayloadConverter::class)
27-
->set('mailer.webhook_request_parser.postmark', PostmarkRequestParser::class)
27+
->set('mailer.webhook.request_parser.postmark', PostmarkRequestParser::class)
2828
->args([service('mailer.payload_converter.postmark')])
29-
->alias(PostmarkRequestParser::class, 'mailer.webhook_request_parser.postmark')
29+
->alias(PostmarkRequestParser::class, 'mailer.webhook.request_parser.postmark')
3030
;
3131
};

src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_webhook.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
return static function (ContainerConfigurator $container) {
1717
$container->services()
18-
->set('notifier.webhook_request_parser.twilio', TwilioRequestParser::class)
19-
->alias(TwilioRequestParser::class, 'notifier.webhook_request_parser.twilio')
18+
->set('notifier.webhook.request_parser.twilio', TwilioRequestParser::class)
19+
->alias(TwilioRequestParser::class, 'notifier.webhook.request_parser.twilio')
2020
;
2121
};

src/Symfony/Bundle/FrameworkBundle/Resources/config/remote_event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$container->services()
1818
->set('remote_event.messenger.handler', ConsumeRemoteEventHandler::class)
1919
->args([
20-
tagged_locator('remote_event.consumer'),
20+
tagged_locator('remote_event.consumer', 'consumer'),
2121
])
2222
->tag('messenger.message_handler')
2323
;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="_webhook_controller" path="/{type}">
8+
<default key="_controller">webhook.controller::handle</default>
9+
</route>
10+
</routes>

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
<xsd:element name="notifier" type="notifier" minOccurs="0" maxOccurs="1" />
4343
<xsd:element name="html-sanitizer" type="html-sanitizer" minOccurs="0" maxOccurs="1" />
4444
<xsd:element name="enabled-locale" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
45-
<xsd:element name="webhook" type="mailer" minOccurs="0" maxOccurs="1" />
46-
<xsd:element name="remote-event" type="mailer" minOccurs="0" maxOccurs="1" />
45+
<xsd:element name="webhook" type="webhook" minOccurs="0" maxOccurs="1" />
46+
<xsd:element name="remote-event" type="remote-event" minOccurs="0" maxOccurs="1" />
4747
</xsd:choice>
4848

4949
<xsd:attribute name="http-method-override" type="xsd:boolean" />
@@ -918,4 +918,23 @@
918918
</xsd:sequence>
919919
<xsd:attribute name="name" type="xsd:string" use="required" />
920920
</xsd:complexType>
921+
922+
<xsd:complexType name="webhook">
923+
<xsd:sequence>
924+
<xsd:element name="routing" type="webhook_routing" minOccurs="0" maxOccurs="unbounded" />
925+
</xsd:sequence>
926+
<xsd:attribute name="enabled" type="xsd:boolean" />
927+
<xsd:attribute name="message-bus" type="xsd:string" />
928+
</xsd:complexType>
929+
930+
<xsd:complexType name="webhook_routing" mixed="true">
931+
<xsd:sequence>
932+
<xsd:element name="service" type="xsd:string" minOccurs="0" maxOccurs="1" />
933+
<xsd:element name="secret" type="xsd:string" minOccurs="0" maxOccurs="1" />
934+
</xsd:sequence>
935+
</xsd:complexType>
936+
937+
<xsd:complexType name="remote-event">
938+
<xsd:attribute name="enabled" type="xsd:boolean" />
939+
</xsd:complexType>
921940
</xsd:schema>

src/Symfony/Bundle/FrameworkBundle/Resources/config/webhook.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
])
4545
->tag('messenger.message_handler')
4646

47-
->set(RequestParser::class, RequestParser::class)
47+
->set('webhook.request_parser', RequestParser::class)
48+
->alias(RequestParser::class, 'webhook.request_parser')
4849

49-
->set(WebhookController::class, WebhookController::class)
50+
->set('webhook.controller', WebhookController::class)
5051
->public()
5152
->args([
5253
abstract_arg('user defined parsers'),
54+
abstract_arg('message bus'),
5355
])
54-
->tag('controller.service_arguments')
5556
;
5657
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
691691
'webhook' => [
692692
'enabled' => false,
693693
'routing' => [],
694+
'message_bus' => 'messenger.default_bus',
694695
],
695696
'remote-event' => [
696697
'enabled' => false,

src/Symfony/Component/Notifier/Bridge/Twilio/Tests/Webhook/TwilioRequestParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected function createRequest(string $payload): Request
3232
]);
3333
}
3434

35-
protected function getFixtureExtension(): string
35+
protected static function getFixtureExtension(): string
3636
{
3737
return 'txt';
3838
}

src/Symfony/Component/RemoteEvent/PayloadConverterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
interface PayloadConverterInterface
1717
{
1818
/**
19-
* @throws ParseException
19+
* @throws ParseException when the payload is not valid
2020
*/
2121
public function convert(array $payload): RemoteEvent;
2222
}

src/Symfony/Component/RemoteEvent/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "symfony/remote-event",
33
"type": "library",
4-
"description": "Ease handling remote events",
4+
"description": "Eases handling remote events",
55
"keywords": ["event"],
66
"homepage": "https://symfony.com",
77
"license": "MIT",

src/Symfony/Component/Webhook/Controller/WebhookController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\Messenger\MessageBusInterface;
1717
use Symfony\Component\RemoteEvent\Messenger\ConsumeRemoteEventMessage;
18-
use Symfony\Component\Routing\Annotation\Route;
1918
use Symfony\Component\Webhook\Client\RequestParserInterface;
2019

2120
/**
@@ -24,17 +23,19 @@
2423
* @author Fabien Potencier <[email protected]>
2524
*
2625
* @experimental in 6.3
26+
*
27+
* @internal
2728
*/
28-
class WebhookController
29+
final class WebhookController
2930
{
3031
public function __construct(
3132
/** @var array<string, array{parser: RequestParserInterface, secret: string}> $parsers */
3233
private array $parsers,
34+
private MessageBusInterface $bus,
3335
) {
3436
}
3537

36-
#[Route('/{type}')]
37-
public function handle(string $type, Request $request, MessageBusInterface $bus): Response
38+
public function handle(string $type, Request $request): Response
3839
{
3940
if (!isset($this->parsers[$type])) {
4041
return new Response(sprintf('No parser found for webhook of type "%s".', $type), 404);
@@ -46,7 +47,7 @@ public function handle(string $type, Request $request, MessageBusInterface $bus)
4647
return $parser->createRejectedResponse('Unable to parse the webhook payload.');
4748
}
4849

49-
$bus->dispatch(new ConsumeRemoteEventMessage($type, $event));
50+
$this->bus->dispatch(new ConsumeRemoteEventMessage($type, $event));
5051

5152
return $parser->createSuccessfulResponse();
5253
}

src/Symfony/Component/Webhook/Subscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Subscriber
1515
{
1616
public function __construct(
1717
private string $url,
18-
private string $secret,
18+
#[\SensitiveParameter] private string $secret,
1919
) {
2020
}
2121

src/Symfony/Component/Webhook/Test/AbstractRequestParserTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public function testParse(string $payload, RemoteEvent $expected)
2929
$this->assertEquals($expected, $wh);
3030
}
3131

32-
public function getPayloads(): iterable
32+
public static function getPayloads(): iterable
3333
{
34-
$currentDir = \dirname((new \ReflectionObject($this))->getFileName());
34+
$currentDir = \dirname((new \ReflectionClass(static::class))->getFileName());
3535
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($currentDir.'/Fixtures', \RecursiveDirectoryIterator::SKIP_DOTS)) as $file) {
3636
$filename = str_replace($currentDir.'/Fixtures/', '', $file->getPathname());
37-
if ($this->getFixtureExtension() !== pathinfo($filename, \PATHINFO_EXTENSION)) {
37+
if (static::getFixtureExtension() !== pathinfo($filename, \PATHINFO_EXTENSION)) {
3838
continue;
3939
}
4040

4141
yield $filename => [
4242
file_get_contents($file),
43-
include(str_replace('.'.$this->getFixtureExtension(), '.php', $file->getPathname())),
43+
include(str_replace('.'.static::getFixtureExtension(), '.php', $file->getPathname())),
4444
];
4545
}
4646
}
@@ -59,7 +59,7 @@ protected function createRequest(string $payload): Request
5959
], $payload);
6060
}
6161

62-
protected function getFixtureExtension(): string
62+
protected static function getFixtureExtension(): string
6363
{
6464
return 'json';
6565
}

src/Symfony/Component/Webhook/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "symfony/webhook",
33
"type": "library",
4-
"description": "Ease sending and consuming webhooks",
4+
"description": "Eases sending and consuming webhooks",
55
"keywords": ["webhook"],
66
"homepage": "https://symfony.com",
77
"license": "MIT",

0 commit comments

Comments
 (0)