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

Skip to content

Commit 232f837

Browse files
committed
[Webhook][RemoteEvent] Add the components
1 parent d0efd41 commit 232f837

File tree

99 files changed

+2757
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2757
-13
lines changed

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"symfony/property-info": "self.version",
9595
"symfony/proxy-manager-bridge": "self.version",
9696
"symfony/rate-limiter": "self.version",
97+
"symfony/remote-event": "self.version",
9798
"symfony/routing": "self.version",
9899
"symfony/security-bundle": "self.version",
99100
"symfony/security-core": "self.version",
@@ -113,6 +114,7 @@
113114
"symfony/var-exporter": "self.version",
114115
"symfony/web-link": "self.version",
115116
"symfony/web-profiler-bundle": "self.version",
117+
"symfony/webhook": "self.version",
116118
"symfony/workflow": "self.version",
117119
"symfony/yaml": "self.version"
118120
},

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class UnusedTagsPass implements CompilerPassInterface
7474
'property_info.list_extractor',
7575
'property_info.type_extractor',
7676
'proxy',
77+
'remote_event.consumer',
7778
'routing.condition_service',
7879
'routing.expression_language_function',
7980
'routing.expression_language_provider',

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
use Symfony\Component\PropertyAccess\PropertyAccessor;
3737
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
3838
use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter;
39+
use Symfony\Component\RemoteEvent\Event;
3940
use Symfony\Component\Semaphore\Semaphore;
4041
use Symfony\Component\Serializer\Serializer;
4142
use Symfony\Component\Translation\Translator;
4243
use Symfony\Component\Uid\Factory\UuidFactory;
4344
use Symfony\Component\Validator\Validation;
45+
use Symfony\Component\Webhook\Controller\WebhookController;
4446
use Symfony\Component\WebLink\HttpHeaderSerializer;
4547
use Symfony\Component\Workflow\WorkflowEvents;
4648

@@ -181,6 +183,8 @@ public function getConfigTreeBuilder(): TreeBuilder
181183
$this->addRateLimiterSection($rootNode, $enableIfStandalone);
182184
$this->addUidSection($rootNode, $enableIfStandalone);
183185
$this->addHtmlSanitizerSection($rootNode, $enableIfStandalone);
186+
$this->addWebhookSection($rootNode, $enableIfStandalone);
187+
$this->addRemoteEventSection($rootNode, $enableIfStandalone);
184188

185189
return $treeBuilder;
186190
}
@@ -2057,6 +2061,46 @@ private function addNotifierSection(ArrayNodeDefinition $rootNode, callable $ena
20572061
;
20582062
}
20592063

2064+
private function addWebhookSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
2065+
{
2066+
$rootNode
2067+
->children()
2068+
->arrayNode('webhook')
2069+
->info('Webhook configuration')
2070+
->{$enableIfStandalone('symfony/webhook', WebhookController::class)}()
2071+
->children()
2072+
->arrayNode('routing')
2073+
->normalizeKeys(false)
2074+
->useAttributeAsKey('type')
2075+
->prototype('array')
2076+
->children()
2077+
->scalarNode('service')
2078+
->isRequired()
2079+
->cannotBeEmpty()
2080+
->end()
2081+
->scalarNode('secret')
2082+
->defaultValue('')
2083+
->end()
2084+
->end()
2085+
->end()
2086+
->end()
2087+
->end()
2088+
->end()
2089+
;
2090+
}
2091+
2092+
private function addRemoteEventSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
2093+
{
2094+
$rootNode
2095+
->children()
2096+
->arrayNode('remote-event')
2097+
->info('RemoteEvent configuration')
2098+
->{$enableIfStandalone('symfony/remote-event', Event::class)}()
2099+
->end()
2100+
->end()
2101+
;
2102+
}
2103+
20602104
private function addRateLimiterSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
20612105
{
20622106
$rootNode

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

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@
9999
use Symfony\Component\Mailer\Bridge\Infobip\Transport\InfobipTransportFactory as InfobipMailerTransportFactory;
100100
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
101101
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
102+
use Symfony\Component\Mailer\Bridge\Mailgun\Webhook\MailgunRequestParser;
102103
use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetTransportFactory;
103104
use Symfony\Component\Mailer\Bridge\MailPace\Transport\MailPaceTransportFactory;
104105
use Symfony\Component\Mailer\Bridge\OhMySmtp\Transport\OhMySmtpTransportFactory;
105106
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
107+
use Symfony\Component\Mailer\Bridge\Postmark\Webhook\PostmarkRequestParser;
106108
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
107109
use Symfony\Component\Mailer\Bridge\Sendinblue\Transport\SendinblueTransportFactory;
108110
use Symfony\Component\Mailer\Command\MailerTestCommand;
@@ -205,6 +207,9 @@
205207
use Symfony\Component\RateLimiter\LimiterInterface;
206208
use Symfony\Component\RateLimiter\RateLimiterFactory;
207209
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;
208213
use Symfony\Component\Routing\Loader\Psr4DirectoryLoader;
209214
use Symfony\Component\Security\Core\AuthenticationEvents;
210215
use Symfony\Component\Security\Core\Exception\AuthenticationException;
@@ -239,6 +244,7 @@
239244
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
240245
use Symfony\Component\Validator\ObjectInitializerInterface;
241246
use Symfony\Component\Validator\Validation;
247+
use Symfony\Component\Webhook\Controller\WebhookController;
242248
use Symfony\Component\WebLink\HttpHeaderSerializer;
243249
use Symfony\Component\Workflow;
244250
use Symfony\Component\Workflow\WorkflowInterface;
@@ -396,7 +402,7 @@ public function load(array $configs, ContainerBuilder $container)
396402
}
397403

398404
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']));
400406

401407
if (!$this->hasConsole() || !class_exists(MailerTestCommand::class)) {
402408
$container->removeDefinition('console.command.mailer_test');
@@ -551,12 +557,20 @@ public function load(array $configs, ContainerBuilder $container)
551557

552558
// notifier depends on messenger, mailer being registered
553559
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']));
555561
}
556562

557563
// profiler depends on form, validation, translation, messenger, mailer, http-client, notifier, serializer being registered
558564
$this->registerProfilerConfiguration($config['profiler'], $container, $loader);
559565

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+
560574
if ($this->readConfigEnabled('html_sanitizer', $container, $config['html_sanitizer'])) {
561575
if (!class_exists(HtmlSanitizerConfig::class)) {
562576
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)
655669
->addTag('messenger.transport_factory');
656670
$container->registerForAutoconfiguration(MimeTypeGuesserInterface::class)
657671
->addTag('mime.mime_type_guesser');
672+
$container->registerForAutoconfiguration(ConsumerInterface::class)
673+
->addTag('remote_event.consumer');
658674
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
659675
->addMethodCall('setLogger', [new Reference('logger')]);
660676

@@ -671,7 +687,9 @@ public function load(array $configs, ContainerBuilder $container)
671687
$container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void {
672688
$definition->addTag('controller.service_arguments');
673689
});
674-
690+
$container->registerAttributeForAutoconfiguration(AsRemoteEventConsumer::class, static function (ChildDefinition $definition, AsRemoteEventConsumer $attribute): void {
691+
$definition->addTag('remote_event.consumer', ['consumer' => $attribute->name]);
692+
});
675693
$container->registerAttributeForAutoconfiguration(AsMessageHandler::class, static function (ChildDefinition $definition, AsMessageHandler $attribute, \ReflectionClass|\ReflectionMethod $reflector): void {
676694
$tagAttributes = get_object_vars($attribute);
677695
$tagAttributes['from_transport'] = $tagAttributes['fromTransport'];
@@ -2435,7 +2453,7 @@ private function registerRetryableHttpClient(array $options, string $name, Conta
24352453
->addTag('monolog.logger', ['channel' => 'http_client']);
24362454
}
24372455

2438-
private function registerMailerConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
2456+
private function registerMailerConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, bool $webhookEnabled)
24392457
{
24402458
if (!class_exists(Mailer::class)) {
24412459
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
24792497
}
24802498
}
24812499

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+
24822513
$envelopeListener = $container->getDefinition('mailer.envelope_listener');
24832514
$envelopeListener->setArgument(0, $config['envelope']['sender'] ?? null);
24842515
$envelopeListener->setArgument(1, $config['envelope']['recipients'] ?? null);
@@ -2501,9 +2532,13 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
25012532
if (!class_exists(MessengerTransportListener::class)) {
25022533
$container->removeDefinition('mailer.messenger_transport_listener');
25032534
}
2535+
2536+
if ($webhookEnabled && class_exists(Event::class)) {
2537+
$loader->load('mailer_webhook.php');
2538+
}
25042539
}
25052540

2506-
private function registerNotifierConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
2541+
private function registerNotifierConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, bool $webhookEnabled)
25072542
{
25082543
if (!class_exists(Notifier::class)) {
25092544
throw new LogicException('Notifier support cannot be enabled as the component is not installed. Try running "composer require symfony/notifier".');
@@ -2666,6 +2701,38 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
26662701
$notifier->addMethodCall('addAdminRecipient', [new Reference($id)]);
26672702
}
26682703
}
2704+
2705+
if ($webhookEnabled && class_exists(Event::class)) {
2706+
$loader->load('notifier_webhook.php');
2707+
}
2708+
}
2709+
2710+
private function registerWebhookConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
2711+
{
2712+
if (!class_exists(WebhookController::class)) {
2713+
throw new LogicException('Webhook support cannot be enabled as the component is not installed. Try running "composer require symfony/webhook".');
2714+
}
2715+
2716+
$loader->load('webhook.php');
2717+
2718+
$parsers = [];
2719+
foreach ($config['routing'] as $type => $config) {
2720+
// FIXME: xml config in the schema to be fixed
2721+
$parsers[$type] = [
2722+
'parser' => $container->findDefinition($config['service']),
2723+
'secret' => $config['secret'],
2724+
];
2725+
}
2726+
$container->getDefinition(WebhookController::class)->replaceArgument(0, $parsers);
2727+
}
2728+
2729+
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
2730+
{
2731+
if (!class_exists(Event::class)) {
2732+
throw new LogicException('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event".');
2733+
}
2734+
2735+
$loader->load('remote_event.php');
26692736
}
26702737

26712738
private function registerRateLimiterConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Mailer\Bridge\Mailgun\RemoteEvent\MailgunPayloadConverter;
15+
use Symfony\Component\Mailer\Bridge\Mailgun\RemoteEvent\PostmarkPayloadConverter;
16+
use Symfony\Component\Mailer\Bridge\Mailgun\Webhook\MailgunRequestParser;
17+
use Symfony\Component\Mailer\Bridge\Postmark\Webhook\PostmarkRequestParser;
18+
19+
return static function (ContainerConfigurator $container) {
20+
$container->services()
21+
->set('mailer.payload_converter.mailgun', MailgunPayloadConverter::class)
22+
->set('mailer.webhook_request_parser.mailgun', MailgunRequestParser::class)
23+
->args([service('mailer.payload_converter.mailgun')])
24+
->alias(MailgunRequestParser::class, 'mailer.webhook_request_parser.mailgun')
25+
26+
->set('mailer.payload_converter.postmark', PostmarkPayloadConverter::class)
27+
->set('mailer.webhook_request_parser.postmark', PostmarkRequestParser::class)
28+
->args([service('mailer.payload_converter.postmark')])
29+
->alias(PostmarkRequestParser::class, 'mailer.webhook_request_parser.postmark')
30+
;
31+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Notifier\Bridge\Twilio\Webhook\TwilioRequestParser;
15+
16+
return static function (ContainerConfigurator $container) {
17+
$container->services()
18+
->set('notifier.webhook_request_parser.twilio', TwilioRequestParser::class)
19+
->alias(TwilioRequestParser::class, 'notifier.webhook_request_parser.twilio')
20+
;
21+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\RemoteEvent\Messenger\ConsumeRemoteEventHandler;
15+
16+
return static function (ContainerConfigurator $container) {
17+
$container->services()
18+
->set('remote_event.messenger.handler', ConsumeRemoteEventHandler::class)
19+
->args([
20+
tagged_locator('remote_event.consumer'),
21+
])
22+
->tag('messenger.message_handler')
23+
;
24+
};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +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" />
4547
</xsd:choice>
4648

4749
<xsd:attribute name="http-method-override" type="xsd:boolean" />

0 commit comments

Comments
 (0)