8000 [Notifier] [Bridges] Provide EventDispatcher and HttpClient to the tr… · symfony/symfony@03dc4c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03dc4c2

Browse files
committed
[Notifier] [Bridges] Provide EventDispatcher and HttpClient to the transports
1 parent 52839be commit 03dc4c2

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -2594,21 +2594,27 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
25942594

25952595
if (ContainerBuilder::willBeAvailable('symfony/mercure-notifier', MercureTransportFactory::class, $parentPackages, true) && ContainerBuilder::willBeAvailable('symfony/mercure-bundle', MercureBundle::class, $parentPackages, true) && \in_array(MercureBundle::class, $container->getParameter('kernel.bundles'), true)) {
25962596
$container->getDefinition($classToServices[MercureTransportFactory::class])
2597-
->replaceArgument('$registry', new Reference(HubRegistry::class));
2597+
->replaceArgument('$registry', new Reference(HubRegistry::class))
2598+
->replaceArgument('$client', new Reference('http_client'))
2599+
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
25982600
} elseif (ContainerBuilder::willBeAvailable('symfony/mercure-notifier', MercureTransportFactory::class, $parentPackages, true)) {
25992601
$container->removeDefinition($classToServices[MercureTransportFactory::class]);
26002602
}
26012603

26022604
if (ContainerBuilder::willBeAvailable('symfony/fake-chat-notifier', FakeChatTransportFactory::class, ['symfony/framework-bundle', 'symfony/notifier', 'symfony/mailer'], true)) {
26032605
$container->getDefinition($classToServices[FakeChatTransportFactory::class])
26042606
->replaceArgument('$mailer', new Reference('mailer'))
2605-
->replaceArgument('$logger', new Reference('logger'));
2607+
->replaceArgument('$logger', new Reference('logger'))
2608+
->replaceArgument('$client', new Reference('http_client'))
2609+
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
26062610
}
26072611

26082612
if (ContainerBuilder::willBeAvailable('symfony/fake-sms-notifier', FakeSmsTransportFactory::class, ['symfony/framework-bundle', 'symfony/notifier', 'symfony/mailer'], true)) {
26092613
$container->getDefinition($classToServices[FakeSmsTransportFactory::class])
26102614
->replaceArgument('$mailer', new Reference('mailer'))
2611-
->replaceArgument('$logger', new Reference('logger'));
2615+
->replaceArgument('$logger', new Reference('logger'))
2616+
->replaceArgument('$client', new Reference('http_client'))
2617+
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
26122618
}
26132619

26142620
if (isset($config['admin_recipients'])) {

src/Symfony/Component/Notifier/Bridge/FakeChat/FakeChatTransportFactory.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
1818
use Symfony\Component\Notifier\Transport\Dsn;
1919
use Symfony\Component\Notifier\Transport\TransportInterface;
20+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
2022

2123
/**
2224
* @author Oskar Stark <oskarstark@googlemail.com>
@@ -27,9 +29,9 @@ final class FakeChatTransportFactory extends AbstractTransportFactory
2729
protected $mailer;
2830
protected $logger;
2931

30-
public function __construct(MailerInterface $mailer, LoggerInterface $logger)
32+
public function __construct(MailerInterface $mailer, LoggerInterface $logger, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
3133
{
32-
parent::__construct();
34+
parent::__construct($dispatcher, $client);
3335

3436
$this->mailer = $mailer;
3537
$this->logger = $logger;
@@ -47,11 +49,11 @@ public function create(Dsn $dsn): TransportInterface
4749
$to = $dsn->getRequiredOption('to');
4850
$from = $dsn->getRequiredOption('from');
4951

50-
return (new FakeChatEmailTransport($this->mailer, $to, $from))->setHost($mailerTransport);
52+
return (new FakeChatEmailTransport($this->mailer, $to, $from, $this->client, $this->dispatcher))->setHost($mailerTransport);
5153
}
5254

5355
if ('fakechat+logger' === $scheme) {
54-
return new FakeChatLoggerTransport($this->logger);
56+
return new FakeChatLoggerTransport($this->logger, $this->client, $this->dispatcher);
5557
}
5658

5759
throw new UnsupportedSchemeException($dsn, 'fakechat', $this->getSupportedSchemes());

src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
1818
use Symfony\Component\Notifier\Transport\Dsn;
1919
use Symfony\Component\Notifier\Transport\TransportInterface;
20+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
2022

2123
/**
2224
* @author James Hemery <james@yieldstudio.fr>
@@ -28,9 +30,9 @@ final class FakeSmsTransportFactory extends AbstractTransportFactory
2830
protected $mailer;
2931
protected $logger;
3032

31-
public function __construct(MailerInterface $mailer, LoggerInterface $logger)
33+
public function __construct(MailerInterface $mailer, LoggerInterface $logger, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
3234
{
33-
parent::__construct();
35+
parent::__construct($dispatcher, $client);
3436

3537
$this->mailer = $mailer;
3638
$this->logger = $logger;
@@ -48,11 +50,11 @@ public function create(Dsn $dsn): TransportInterface
4850
$to = $dsn->getRequiredOption('to');
4951
$from = $dsn->getRequiredOption('from');
5052

51-
return (new FakeSmsEmailTransport($this->mailer, $to, $from))->setHost($mailerTransport);
53+
return (new FakeSmsEmailTransport($this->mailer, $to, $from, $this->client, $this->dispatcher))->setHost($mailerTransport);
5254
}
5355

5456
if ('fakesms+logger' === $scheme) {
55-
return new FakeSmsLoggerTransport($this->logger);
57+
return new FakeSmsLoggerTransport($this->logger, $this->client, $this->dispatcher);
5658
}
5759

5860
throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());

src/Symfony/Component/Notifier/Bridge/Mercure/MercureTransportFactory.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
1919
use Symfony\Component\Notifier\Transport\Dsn;
2020
use Symfony\Component\Notifier\Transport\TransportInterface;
21+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
22+
use Symfony\Contracts\HttpClient\HttpClientInterface;
2123

2224
/**
2325
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
@@ -26,9 +28,9 @@ final class MercureTransportFactory extends AbstractTransportFactory
2628
{
2729
private $registry;
2830

29-
public function __construct(HubRegistry $registry)
31+
public function __construct(HubRegistry $registry, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
3032
{
31-
parent::__construct();
33+
parent::__construct($dispatcher, $client);
3234

3335
$this->registry = $registry;
3436
}
@@ -51,7 +53,7 @@ public function create(Dsn $dsn): TransportInterface
5153
throw new IncompleteDsnException(sprintf('Hub "%s" not found. Did you mean one of: "%s"?', $hubId, implode('", "', array_keys($this->registry->all()))));
5254
}
5355

54-
return new MercureTransport($hub, $hubId, $topic);
56+
return new MercureTransport($hub, $hubId, $topic, $this->client, $this->dispatcher);
5557
}
5658

5759
protected function getSupportedSchemes(): array

0 commit comments

Comments
 (0)
0