-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
Romain Mouillard
committed
Nov 14, 2018
1 parent
d431d9d
commit 4a822bd
Showing
12 changed files
with
267 additions
and
119 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
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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\UserBundle\Mailer; | ||
|
||
use FOS\UserBundle\Mailer\MailerInterface; | ||
use FOS\UserBundle\Model\UserInterface; | ||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
final class Mailer implements MailerInterface | ||
{ | ||
/** | ||
* @var UrlGeneratorInterface | ||
*/ | ||
private $urlGenerator; | ||
|
||
/** | ||
* @var EngineInterface | ||
*/ | ||
private $templating; | ||
|
||
/** | ||
* @var \Swift_Mailer | ||
*/ | ||
private $mailer; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $fromEmail; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $emailTemplate; | ||
|
||
public function __construct(UrlGeneratorInterface $urlGenerator, EngineInterface $templating, \Swift_Mailer $mailer, array $fromEmail, string $emailTemplate) | ||
{ | ||
$this->urlGenerator = $urlGenerator; | ||
$this->templating = $templating; | ||
$this->mailer = $mailer; | ||
$this->fromEmail = $fromEmail; | ||
$this->emailTemplate = $emailTemplate; | ||
} | ||
|
||
public function sendResettingEmailMessage(UserInterface $user): void | ||
{ | ||
$url = $this->urlGenerator->generate('sonata_user_admin_resetting_reset', [ | ||
'token' => $user->getConfirmationToken(), | ||
], UrlGeneratorInterface::ABSOLUTE_URL); | ||
|
||
$rendered = $this->templating->render($this->emailTemplate, [ | ||
'user' => $user, | ||
'confirmationUrl' => $url, | ||
]); | ||
|
||
// Render the email, use the first line as the subject, and the rest as the body | ||
$renderedLines = explode(PHP_EOL, trim($rendered)); | ||
$subject = array_shift($renderedLines); | ||
$body = implode(PHP_EOL, $renderedLines); | ||
$message = (new \Swift_Message()) | ||
->setSubject($subject) | ||
->setFrom($this->fromEmail) | ||
->setTo((string) $user->getEmail()) | ||
->setBody($body); | ||
|
||
$this->mailer->send($message); | ||
} | ||
|
||
public function sendConfirmationEmailMessage(UserInterface $user): void | ||
{ | ||
throw new \LogicException('This method is not implemented.'); | ||
} | ||
} |
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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="sonata.user.mailer.default" class="Sonata\UserBundle\Mailer\Mailer"> | ||
<argument type="service" id="router"/> | ||
<argument type="service" id="sonata.templating"/> | ||
<argument type="service" id="mailer"/> | ||
<argument>%fos_user.resetting.email.from_email%</argument> | ||
<argument>%fos_user.resetting.email.template%</argument> | ||
</service> | ||
</services> | ||
</container> |
Oops, something went wrong.