Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c9d684

Browse files
committed
[Mime] added BodyRendererInterface
1 parent19c6639 commit0c9d684

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

‎src/Symfony/Bridge/Twig/Mime/Renderer.php‎renamed to ‎src/Symfony/Bridge/Twig/Mime/BodyRenderer.php‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
namespaceSymfony\Bridge\Twig\Mime;
1313

1414
useLeague\HTMLToMarkdown\HtmlConverter;
15+
useSymfony\Component\Mime\BodyRendererInterface;
16+
useSymfony\Component\Mime\Message;
1517
useTwig\Environment;
1618

1719
/**
1820
* @author Fabien Potencier <fabien@symfony.com>
1921
*
2022
* @experimental in 4.3
2123
*/
22-
finalclassRenderer
24+
finalclassBodyRendererimplements BodyRendererInterface
2325
{
2426
private$twig;
2527
private$context;
@@ -38,48 +40,48 @@ public function __construct(Environment $twig, array $context = [])
3840
}
3941
}
4042

41-
publicfunctionrender(TemplatedEmail$email):TemplatedEmail
43+
publicfunctionrender(Message$message):void
4244
{
43-
$email =clone$email;
45+
if (!$messageinstanceof TemplatedEmail) {
46+
return;
47+
}
4448

45-
$vars =array_merge($this->context,$email->getContext(), [
46-
'email' =>newWrappedTemplatedEmail($this->twig,$email),
49+
$vars =array_merge($this->context,$message->getContext(), [
50+
'email' =>newWrappedTemplatedEmail($this->twig,$message),
4751
]);
4852

49-
if ($template =$email->getTemplate()) {
50-
$this->renderFull($email,$template,$vars);
53+
if ($template =$message->getTemplate()) {
54+
$this->renderFull($message,$template,$vars);
5155
}
5256

53-
if ($template =$email->getTextTemplate()) {
54-
$email->text($this->twig->render($template,$vars));
57+
if ($template =$message->getTextTemplate()) {
58+
$message->text($this->twig->render($template,$vars));
5559
}
5660

57-
if ($template =$email->getHtmlTemplate()) {
58-
$email->html($this->twig->render($template,$vars));
61+
if ($template =$message->getHtmlTemplate()) {
62+
$message->html($this->twig->render($template,$vars));
5963
}
6064

6165
// if text body is empty, compute one from the HTML body
62-
if (!$email->getTextBody() &&null !==$html =$email->getHtmlBody()) {
63-
$email->text($this->convertHtmlToText(\is_resource($html) ?stream_get_contents($html) :$html));
66+
if (!$message->getTextBody() &&null !==$html =$message->getHtmlBody()) {
67+
$message->text($this->convertHtmlToText(\is_resource($html) ?stream_get_contents($html) :$html));
6468
}
65-
66-
return$email;
6769
}
6870

69-
privatefunctionrenderFull(TemplatedEmail$email,string$template,array$vars):void
71+
privatefunctionrenderFull(TemplatedEmail$message,string$template,array$vars):void
7072
{
7173
$template =$this->twig->load($template);
7274

7375
if ($template->hasBlock('subject',$vars)) {
74-
$email->subject($template->renderBlock('subject',$vars));
76+
$message->subject($template->renderBlock('subject',$vars));
7577
}
7678

7779
if ($template->hasBlock('text',$vars)) {
78-
$email->text($template->renderBlock('text',$vars));
80+
$message->text($template->renderBlock('text',$vars));
7981
}
8082

8183
if ($template->hasBlock('html',$vars)) {
82-
$email->html($template->renderBlock('html',$vars));
84+
$message->html($template->renderBlock('html',$vars));
8385
}
8486

8587
if ($template->hasBlock('config',$vars)) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Mime;
13+
14+
/**
15+
* @author Fabien Potencier <fabien@symfony.com>
16+
*
17+
* @experimental in 4.3
18+
*/
19+
interface BodyRendererInterface
20+
{
21+
publicfunctionrender(Message$message):void;
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp