Skip to content
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

FIX Use TransportFactory to prevent infinite config loop #10898

Merged
merged 1 commit into from
Aug 1, 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
13 changes: 1 addition & 12 deletions _config/mailer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 21 additions & 0 deletions src/Control/Email/TransportFactory.php
Original file line number Diff line number Diff line change
@@ -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);
}
}