Exemple #1
0
 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function provideEmailWithoutTemplate(EmailInterface $email, array $data)
 {
     $twig = new \Twig_Environment(new \Twig_Loader_Array([]));
     $subjectTemplate = $twig->createTemplate($email->getSubject());
     $bodyTemplate = $twig->createTemplate($email->getContent());
     $subject = $subjectTemplate->render($data);
     $body = $bodyTemplate->render($data);
     return new RenderedEmail($subject, $body);
 }
Exemple #2
0
 function it_creates_and_renders_an_email(EmailInterface $email, EventDispatcherInterface $dispatcher, EmailRenderEvent $event, RenderedEmail $renderedEmail)
 {
     $this->setEventDispatcher($dispatcher);
     $email->getTemplate()->shouldBeCalled()->willReturn(null);
     $email->getSubject()->shouldBeCalled()->willReturn('subject');
     $email->getContent()->shouldBeCalled()->willReturn('content');
     $dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_RENDER, Argument::type(EmailRenderEvent::class))->shouldBeCalled()->willReturn($event);
     $event->getRenderedEmail()->shouldBeCalled()->willReturn($renderedEmail);
     $this->render($email, array())->shouldReturn($renderedEmail);
 }
Exemple #3
0
 /**
  * @param EmailInterface $email
  * @param array $data
  *
  * @return RenderedEmail
  */
 private function getRenderedEmail(EmailInterface $email, array $data)
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         $subject = $template->renderBlock('subject', $data);
         $body = $template->renderBlock('body', $data);
         return new RenderedEmail($subject, $body);
     }
     $twig = new \Twig_Environment(new \Twig_Loader_Array([]));
     $subjectTemplate = $twig->createTemplate($email->getSubject());
     $bodyTemplate = $twig->createTemplate($email->getContent());
     $subject = $subjectTemplate->render($data);
     $body = $bodyTemplate->render($data);
     return new RenderedEmail($subject, $body);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function render(EmailInterface $email, array $data = array())
 {
     if (null !== $email->getTemplate()) {
         $data = $this->twig->mergeGlobals($data);
         /** @var \Twig_Template $template */
         $template = $this->twig->loadTemplate($email->getTemplate());
         $subject = $template->renderBlock('subject', $data);
         $body = $template->renderBlock('body', $data);
     } else {
         $twig = new \Twig_Environment(new \Twig_Loader_Array(array()));
         $subjectTemplate = $twig->createTemplate($email->getSubject());
         $bodyTemplate = $twig->createTemplate($email->getContent());
         $subject = $subjectTemplate->render($data);
         $body = $bodyTemplate->render($data);
     }
     /** @var EmailRenderEvent $event */
     $event = $this->dispatcher->dispatch(SyliusMailerEvents::EMAIL_PRE_RENDER, new EmailRenderEvent(new RenderedEmail($subject, $body)));
     return $event->getRenderedEmail();
 }