Skip to content
Snippets Groups Projects

Issue #3394123: Add Symfony Messenger support for async messsages (emails as queues)

12 files
+ 473
37
Compare changes
  • Side-by-side
  • Inline
Files
12
+ 54
0
<?php
declare(strict_types = 1);
namespace Drupal\symfony_mailer;
use Drupal\Core\Entity\EntityTypeManagerInterface;
/**
* Repository of mailer transport DSNs.
*
* This is needed since we need to be able to reverse DSN to the transport
* key due to concepts introduced by this project. EmailAdjuster is able to call
* \Drupal\symfony_mailer\EmailInterface::setTransportDsn, rather than setting
* the transport name.
*/
final class Connections {
public function __construct(
private EntityTypeManagerInterface $entityTypeManager,
)
{
}
/**
* Get DSNs by name.
*
* By convention, the first item is the default.
*
* @see https://symfony.com/doc/current/mailer.html#multiple-email-transports
*/
public function getDsns(): array {
/** @var \Drupal\symfony_mailer\Entity\MailerTransport[] $transports */
$transports = $this->entityTypeManager
->getStorage('mailer_transport')
->loadMultiple();
$result = [];
foreach ($transports as $transport) {
$result[$transport->id()] = $transport->getDsn();
}
return $result;
}
public function getTransportNameFromDsn(string $dsn): ?string {
$key = array_search($dsn, $this->getDsns());
return $key !== FALSE ? $key : NULL;
}
public function getDefaultTransportName(): ?string {
return array_key_first($this->getDsns());
}
}
Loading