1212namespace Symfony \Bridge \Twig \Mime ;
1313
1414use League \HTMLToMarkdown \HtmlConverter ;
15+ use Symfony \Component \Mime \BodyRendererInterface ;
16+ use Symfony \Component \Mime \Message ;
1517use Twig \Environment ;
1618
1719/**
1820 * @author Fabien Potencier <fabien@symfony.com>
1921 *
2022 * @experimental in 4.3
2123 */
22- final class Renderer
24+ final class BodyRenderer implements BodyRendererInterface
2325{
2426private $ twig ;
2527private $ context ;
@@ -38,48 +40,48 @@ public function __construct(Environment $twig, array $context = [])
3840 }
3941 }
4042
41- public function render (TemplatedEmail $ email ):TemplatedEmail
43+ public function render (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 ' =>new WrappedTemplatedEmail ($ this ->twig ,$ email ),
49+ $ vars =array_merge ($ this ->context ,$ message ->getContext (), [
50+ 'email ' =>new WrappedTemplatedEmail ($ 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- private function renderFull (TemplatedEmail $ email ,string $ template ,array $ vars ):void
71+ private function renderFull (TemplatedEmail $ message ,string $ template ,array $ vars ):void
7072 {
7173$ template =$ this ->twig ->load ($ template );
7274
7375if ($ template ->hasBlock ('subject ' ,$ vars )) {
74- $ email ->subject ($ template ->renderBlock ('subject ' ,$ vars ));
76+ $ message ->subject ($ template ->renderBlock ('subject ' ,$ vars ));
7577 }
7678
7779if ($ template ->hasBlock ('text ' ,$ vars )) {
78- $ email ->text ($ template ->renderBlock ('text ' ,$ vars ));
80+ $ message ->text ($ template ->renderBlock ('text ' ,$ vars ));
7981 }
8082
8183if ($ template ->hasBlock ('html ' ,$ vars )) {
82- $ email ->html ($ template ->renderBlock ('html ' ,$ vars ));
84+ $ message ->html ($ template ->renderBlock ('html ' ,$ vars ));
8385 }
8486
8587if ($ template ->hasBlock ('config ' ,$ vars )) {