mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Use TransportFactory to prevent infinite config loop
This commit is contained in:
parent
067a3e25b8
commit
c58bc0a7ff
@ -11,18 +11,7 @@ SilverStripe\Core\Injector\Injector:
|
||||
calls:
|
||||
- [addSubscriber, ['%$SilverStripe\Control\Email\MailerSubscriber']]
|
||||
Symfony\Component\Mailer\Transport\TransportInterface:
|
||||
factory: Symfony\Component\Mailer\Transport
|
||||
factory_method: fromDsn
|
||||
factory: SilverStripe\Control\Email\TransportFactory
|
||||
constructor:
|
||||
dsn: 'sendmail://default'
|
||||
dispatcher: '%$Symfony\Component\EventDispatcher\EventDispatcherInterface.mailer'
|
||||
---
|
||||
Name: mailer-dsn-env
|
||||
After: '*'
|
||||
Only:
|
||||
envvarset: MAILER_DSN
|
||||
---
|
||||
SilverStripe\Core\Injector\Injector:
|
||||
Symfony\Component\Mailer\Transport\TransportInterface:
|
||||
constructor:
|
||||
dsn: '`MAILER_DSN`'
|
||||
|
21
src/Control/Email/TransportFactory.php
Normal file
21
src/Control/Email/TransportFactory.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Control\Email;
|
||||
|
||||
use SilverStripe\Core\Environment;
|
||||
use SilverStripe\Core\Injector\Factory;
|
||||
use Symfony\Component\Mailer\Transport;
|
||||
|
||||
/**
|
||||
* Creates an email transport from a DSN string
|
||||
* A DSN defined in an environment variable has priority over a DSN defined in yml config file
|
||||
*/
|
||||
class TransportFactory implements Factory
|
||||
{
|
||||
public function create($service, array $params = [])
|
||||
{
|
||||
$dsn = Environment::getEnv('MAILER_DSN') ?: $params['dsn'];
|
||||
$dispatcher = $params['dispatcher'];
|
||||
return Transport::fromDsn($dsn, $dispatcher);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user