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 12namespace Symfony\Bundle\MonologBundle\SwiftMailer; 13 14/** 15 * Helps create Swift_Message objects, lazily 16 * 17 * @author Ryan Weaver <ryan@knpuniversity.com> 18 */ 19class MessageFactory 20{ 21 private $mailer; 22 23 private $fromEmail; 24 25 private $toEmail; 26 27 private $subject; 28 29 private $contentType; 30 31 public function __construct(\Swift_Mailer $mailer, $fromEmail, $toEmail, $subject, $contentType = null) 32 { 33 $this->mailer = $mailer; 34 $this->fromEmail = $fromEmail; 35 $this->toEmail = $toEmail; 36 $this->subject = $subject; 37 $this->contentType = $contentType; 38 } 39 40 /** 41 * Creates a Swift_Message template that will be used to send the log message 42 * 43 * @param string $content formatted email body to be sent 44 * @param array $records Log records that formed the content 45 * @return \Swift_Message 46 */ 47 public function createMessage($content, array $records) 48 { 49 /** @var \Swift_Message $message */ 50 $message = $this->mailer->createMessage(); 51 $message->setTo($this->toEmail); 52 $message->setFrom($this->fromEmail); 53 $message->setSubject($this->subject); 54 55 if ($this->contentType) { 56 $message->setContentType($this->contentType); 57 } 58 59 return $message; 60 } 61} 62