Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
685 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Symfony/Component/Mailer/Bridge/Amazon/Factory/SesTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Amazon\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Amazon; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class SesTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
$scheme = $dsn->getScheme(); | ||
$user = $dsn->getUser(); | ||
$pass = $dsn->getPass(); | ||
$region = $dsn->getOption('region'); | ||
|
||
if ('smtp' === $scheme) { | ||
return new Amazon\Smtp\SesTransport($user, $pass, $region, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('api' === $scheme) { | ||
return new Amazon\Http\Api\SesTransport($user, $pass, $region, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('http' === $scheme) { | ||
return new Amazon\Http\SesTransport($user, $pass, $region, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'ses' === $dsn->getHost(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Symfony/Component/Mailer/Bridge/Google/Factory/GmailTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Google\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Google\Smtp\GmailTransport; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class GmailTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
if ('smtp' === $dsn->getScheme()) { | ||
return new GmailTransport($dsn->getUser(), $dsn->getPass(), $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'gmail' === $dsn->getHost(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Symfony/Component/Mailer/Bridge/Mailchimp/Factory/MandrillTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Mailchimp\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Mailchimp; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class MandrillTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
$scheme = $dsn->getScheme(); | ||
$user = $dsn->getUser(); | ||
|
||
if ('smtp' === $scheme) { | ||
return new Mailchimp\Smtp\MandrillTransport($user, $dsn->getPass(), $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('api' === $scheme) { | ||
return new Mailchimp\Http\Api\MandrillTransport($user, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('http' === $scheme) { | ||
return new Mailchimp\Http\MandrillTransport($user, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'mandrill' === $dsn->getHost(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Symfony/Component/Mailer/Bridge/Mailgun/Factory/MailgunTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Mailgun\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Mailgun; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class MailgunTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
$scheme = $dsn->getScheme(); | ||
$user = $dsn->getUser(); | ||
$pass = $dsn->getPass(); | ||
|
||
if ('smtp' === $scheme) { | ||
return new Mailgun\Smtp\MailgunTransport($user, $pass, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('http' === $scheme) { | ||
return new Mailgun\Http\MailgunTransport($user, $pass, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('api' === $scheme) { | ||
return new Mailgun\Http\Api\MailgunTransport($user, $pass, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'mailgun' === $dsn->getHost(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/Symfony/Component/Mailer/Bridge/Postmark/Factory/PostmarkTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Postmark\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Postmark; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class PostmarkTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
$scheme = $dsn->getScheme(); | ||
$user = $dsn->getUser(); | ||
|
||
if ('smtp' === $scheme) { | ||
return new Postmark\Smtp\PostmarkTransport($user, $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('api' === $scheme) { | ||
return new Postmark\Http\Api\PostmarkTransport($user, $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'postmark' === $dsn->getHost(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Symfony/Component/Mailer/Bridge/Sendgrid/Factory/SendgridTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Sendgrid\Factory; | ||
|
||
use Symfony\Component\Mailer\Bridge\Sendgrid; | ||
use Symfony\Component\Mailer\Exception\InvalidDsnException; | ||
use Symfony\Component\Mailer\Transport\AbstractTransportFactory; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
use Symfony\Component\Mailer\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class SendgridTransportFactory extends AbstractTransportFactory | ||
{ | ||
public function create(Dsn $dsn): TransportInterface | ||
{ | ||
if ('smtp' === $dsn->getScheme()) { | ||
return new Sendgrid\Smtp\SendgridTransport($dsn->getUser(), $this->dispatcher, $this->logger); | ||
} | ||
|
||
if ('api' === $dsn->getScheme()) { | ||
return new Sendgrid\Http\Api\SendgridTransport($dsn->getUser(), $this->client, $this->dispatcher, $this->logger); | ||
} | ||
|
||
throw InvalidDsnException::unsupportedScheme($dsn); | ||
} | ||
|
||
public function supports(Dsn $dsn): bool | ||
{ | ||
return 'sendgrid' === $dsn->getHost(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/Mailer/Exception/InvalidDsnException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Exception; | ||
|
||
use Symfony\Component\Mailer\Bridge; | ||
use Symfony\Component\Mailer\Transport\Dsn; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
class InvalidDsnException extends LogicException | ||
{ | ||
public static function unsupportedScheme(Dsn $dsn): self | ||
{ | ||
return new self(sprintf('The "%s" scheme is not supported for mailer "%s".', $dsn->getScheme(), $dsn->getHost())); | ||
} | ||
|
||
public static function unsupportedHost(Dsn $dsn): self | ||
{ | ||
$hostsToPackages = [ | ||
'gmail' => [ | ||
'class' => Bridge\Google\Factory\GmailTransportFactory::class, | ||
'package' => 'symfony/google-mailer', | ||
], | ||
'mailgun' => [ | ||
'class' => Bridge\Mailgun\Factory\MailgunTransportFactory::class, | ||
'package' => 'symfony/mailgun-mailer', | ||
], | ||
'postmark' => [ | ||
'class' => Bridge\Postmark\Factory\PostmarkTransportFactory::class, | ||
'package' => 'symfony/postmark-mailer', | ||
], | ||
'sendgrid' => [ | ||
'class' => Bridge\Sendgrid\Factory\SendgridTransportFactory::class, | ||
'package' => 'symfony/sendgrid-mailer', | ||
], | ||
'ses' => [ | ||
'class' => Bridge\Amazon\Factory\SesTransportFactory::class, | ||
'package' => 'symfony/amazon-mailer', | ||
], | ||
'mandrill' => [ | ||
'class' => Bridge\Mailchimp\Factory\MandrillTransportFactory::class, | ||
'package' => 'symfony/mailchimp-mailer', | ||
], | ||
]; | ||
|
||
$host = $dsn->getHost(); | ||
$package = $hostsToPackages[$host] ?? null; | ||
if ($package && !class_exists($package['class'])) { | ||
return new self(sprintf('Unable to send emails via "%s" as the bridge is not installed. Try running "composer require %s".', $host, $package['package'])); | ||
} | ||
|
||
return new self(sprintf('The "%s" mailer is not supported.', $host)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Component/Mailer/Transport/AbstractTransportFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Transport; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @author Konstantin Myakshin <molodchick@gmail.com> | ||
*/ | ||
abstract class AbstractTransportFactory implements TransportFactoryInterface | ||
{ | ||
protected $client; | ||
protected $dispatcher; | ||
protected $logger; | ||
|
||
public function __construct(HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) | ||
{ | ||
$this->client = $client; | ||
$this->dispatcher = $dispatcher; | ||
$this->logger = $logger; | ||
} | ||
} |
Oops, something went wrong.