Skip to content

[Notifier] [Bridges] Provide EventDispatcher and HttpClient to the transport #52998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2594,21 +2594,27 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $

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)) {
$container->getDefinition($classToServices[MercureTransportFactory::class])
->replaceArgument('$registry', new Reference(HubRegistry::class));
->replaceArgument('$registry', new Reference(HubRegistry::class))
->replaceArgument('$client', new Reference('http_client'))
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
} elseif (ContainerBuilder::willBeAvailable('symfony/mercure-notifier', MercureTransportFactory::class, $parentPackages, true)) {
$container->removeDefinition($classToServices[MercureTransportFactory::class]);
}

if (ContainerBuilder::willBeAvailable('symfony/fake-chat-notifier', FakeChatTransportFactory::class, ['symfony/framework-bundle', 'symfony/notifier', 'symfony/mailer'], true)) {
$container->getDefinition($classToServices[FakeChatTransportFactory::class])
->replaceArgument('$mailer', new Reference('mailer'))
->replaceArgument('$logger', new Reference('logger'));
->replaceArgument('$logger', new Reference('logger'))
->replaceArgument('$client', new Reference('http_client'))
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
}

if (ContainerBuilder::willBeAvailable('symfony/fake-sms-notifier', FakeSmsTransportFactory::class, ['symfony/framework-bundle', 'symfony/notifier', 'symfony/mailer'], true)) {
$container->getDefinition($classToServices[FakeSmsTransportFactory::class])
->replaceArgument('$mailer', new Reference('mailer'))
->replaceArgument('$logger', new Reference('logger'));
->replaceArgument('$logger', new Reference('logger'))
->replaceArgument('$client', new Reference('http_client'))
->replaceArgument('$dispatcher', new Reference('event_dispatcher'));
}

if (isset($config['admin_recipients'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

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

public function __construct(MailerInterface $mailer, LoggerInterface $logger)
public function __construct(MailerInterface $mailer, LoggerInterface $logger, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
{
parent::__construct();
parent::__construct($dispatcher, $client);

$this->mailer = $mailer;
$this->logger = $logger;
Expand All @@ -47,11 +49,11 @@ public function create(Dsn $dsn): TransportInterface
$to = $dsn->getRequiredOption('to');
$from = $dsn->getRequiredOption('from');

return (new FakeChatEmailTransport($this->mailer, $to, $from))->setHost($mailerTransport);
return (new FakeChatEmailTransport($this->mailer, $to, $from, $this->client, $this->dispatcher))->setHost($mailerTransport);
}

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

throw new UnsupportedSchemeException($dsn, 'fakechat', $this->getSupportedSchemes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

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

public function __construct(MailerInterface $mailer, LoggerInterface $logger)
public function __construct(MailerInterface $mailer, LoggerInterface $logger, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
{
parent::__construct();
parent::__construct($dispatcher, $client);

$this->mailer = $mailer;
$this->logger = $logger;
Expand All @@ -48,11 +50,11 @@ public function create(Dsn $dsn): TransportInterface
$to = $dsn->getRequiredOption('to');
$from = $dsn->getRequiredOption('from');

return (new FakeSmsEmailTransport($this->mailer, $to, $from))->setHost($mailerTransport);
return (new FakeSmsEmailTransport($this->mailer, $to, $from, $this->client, $this->dispatcher))->setHost($mailerTransport);
}

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

throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

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

public function __construct(HubRegistry $registry)
public function __construct(HubRegistry $registry, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null)
{
parent::__construct();
parent::__construct($dispatcher, $client);

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

return new MercureTransport($hub, $hubId, $topic);
return new MercureTransport($hub, $hubId, $topic, $this->client, $this->dispatcher);
}

protected function getSupportedSchemes(): array
Expand Down