-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an adapter to support the Symfony Mailer component and deprecate …
…the Swiftmailer integration Co-authored-by: Michael Babker <[email protected]>
- Loading branch information
Showing
15 changed files
with
350 additions
and
122 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
/composer.phar | ||
/composer.lock | ||
|
||
/.phpunit.result.cache |
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
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
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
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
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
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
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,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Sender\Adapter; | ||
|
||
use Sylius\Component\Mailer\Event\EmailSendEvent; | ||
use Sylius\Component\Mailer\Model\EmailInterface; | ||
use Sylius\Component\Mailer\Renderer\RenderedEmail; | ||
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter; | ||
use Sylius\Component\Mailer\SyliusMailerEvents; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\Mime\Address; | ||
use Symfony\Component\Mime\Email; | ||
|
||
final class SymfonyMailerAdapter extends AbstractAdapter | ||
{ | ||
private MailerInterface $mailer; | ||
|
||
public function __construct(MailerInterface $mailer) | ||
{ | ||
$this->mailer = $mailer; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function send( | ||
array $recipients, | ||
string $senderAddress, | ||
string $senderName, | ||
RenderedEmail $renderedEmail, | ||
EmailInterface $email, | ||
array $data, | ||
array $attachments = [], | ||
array $replyTo = [] | ||
): void { | ||
$message = (new Email()) | ||
->subject($renderedEmail->getSubject()) | ||
->from(new Address($senderAddress, $senderName)) | ||
->to(...$recipients) | ||
->replyTo(...$replyTo) | ||
->html($renderedEmail->getBody()); | ||
|
||
foreach ($attachments as $attachment) { | ||
$message->attachFromPath($attachment); | ||
} | ||
|
||
$emailSendEvent = new EmailSendEvent($message, $email, $data, $recipients, $replyTo); | ||
|
||
$this->dispatcher?->dispatch($emailSendEvent, SyliusMailerEvents::EMAIL_PRE_SEND); | ||
|
||
$this->mailer->send($message); | ||
|
||
$this->dispatcher?->dispatch($emailSendEvent, SyliusMailerEvents::EMAIL_POST_SEND); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
namespace spec\Sylius\Bundle\MailerBundle\Sender\Adapter; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\MailerBundle\Sender\Adapter\SwiftMailerAdapter; | ||
use Sylius\Bundle\MailerBundle\Sender\Adapter\SymfonyMailerAdapter; | ||
use Sylius\Component\Mailer\Model\EmailInterface; | ||
use Sylius\Component\Mailer\Renderer\RenderedEmail; | ||
use Sylius\Component\Mailer\Sender\Adapter\AbstractAdapter; | ||
|
@@ -32,8 +32,8 @@ function it_throws_an_exception_about_not_configured_email_sender_adapter( | |
): void { | ||
$this | ||
->shouldThrow(new \RuntimeException(sprintf( | ||
'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/swiftmailer-bundle" library).', | ||
SwiftMailerAdapter::class | ||
'You need to configure an adapter to send the email. Take a look at %s (requires "symfony/mailer" library).', | ||
SymfonyMailerAdapter::class | ||
))) | ||
->during('send', [['[email protected]'], '[email protected]', 'arnaud', $renderedEmail, $email, []]) | ||
; | ||
|
Oops, something went wrong.