/**
  * @param $message
  * @param string $destination
  * @param null $transport
  * @return MailgunMessage|\PHPMailer|\Swift_Message|Message
  * @throws MailWrapperSetupException
  */
 public static function convert($message, $destination = 'wrappedMessage', $transport = null)
 {
     switch (true) {
         case $message instanceof MailWrappedMessage:
             break;
         case $message instanceof Message:
             $message = MessageTransformerZend::toWrappedMessage($message);
             break;
         case $message instanceof MessageBuilder:
             $message = MessageTransformerMailgun::toWrappedMessage($message);
             break;
         case $message instanceof \PHPMailer:
             $message = MessageTransformerPhpMailer::toWrappedMessage($message);
             break;
         case $message instanceof \Swift_Message:
             $message = MessageTransformerSwift::toWrappedMessage($message);
             break;
         default:
             throw new MailWrapperSetupException('No Message Converter');
     }
     switch ($destination) {
         case 'mailgun':
             return MessageTransformerMailgun::fromWrappedMessage($message, $transport);
         case 'phpmailer':
             return MessageTransformerPhpMailer::fromWrappedMessage($message);
         case 'swift':
             return MessageTransformerSwift::fromWrappedMessage($message);
         case 'zend':
             return MessageTransformerZend::fromWrappedMessage($message);
         case 'wrappedMessage':
             return $message;
         default:
             throw new MailWrapperSetupException('No Message Converter');
     }
 }
 /**
  * @param TransportInterface $transport
  * @param MailWrappedMessage|Message $message
  * @return mixed
  * @throws MailWrapperSetupException
  */
 public static function send(TransportInterface $transport, $message = null)
 {
     if (!$message instanceof Message) {
         $message = MessageTransformerZend::fromWrappedMessage($message);
     }
     return $transport->send($message);
 }
Пример #3
0
 /**
  *
  */
 public function testValidTo()
 {
     $wrappedMessage = TesterWrappedMessage::getValid();
     $message = MessageTransformerZend::fromWrappedMessage($wrappedMessage);
     $this->assertInstanceOf('Zend\\Mail\\Message', $message);
     $this->assertCount(2, $message->getTo());
     $this->assertCount(2, $message->getCc());
     $this->assertCount(2, $message->getBcc());
     $this->assertGreaterThan(0, strlen($message->getSubject()));
     $this->assertGreaterThan(0, strlen($message->getBody()));
 }