/** * @return array|bool * @throws MailWrapperSendException * @throws MailWrapperSetupException */ public static function send() { $args = func_get_args(); $message = array_shift($args); // re-add message to args as PHPMailer is both transport and message if ($message instanceof \PHPMailer) { $args[] = $message; } $message = MessageTransformer::convert($message); if (!count($args)) { throw new MailWrapperSetupException('No Transports available'); } foreach ($args as $transport) { if (!$transport) { throw new MailWrapperSetupException('NULL Transport'); } try { return static::sendVia($transport, $message); } catch (\Exception $e) { if ($e instanceof MailWrapperSetupException) { throw $e; } if (self::$debug) { throw $e; } continue; } } throw new MailWrapperSendException('No Transports succeeded'); }
/** * */ public function testConvert() { $transport = MailgunManager::newInstance('TEST', 'example.com'); $message = TesterMessageMailgun::getValid(); $newMessage = MessageTransformer::convert($message, 'mailgun', $transport); $this->assertInstanceOf('BespokeSupport\\MailWrapper\\MailgunMessage', $newMessage); }
/** * @param null $message * @return MailWrappedMessage * @throws MailWrapperSetupException */ public static function newInstance($message = null) { switch (true) { case $message instanceof Swift_Message: case $message instanceof PHPMailer: case $message instanceof MessageBuilder: case $message instanceof Message: case $message instanceof MailWrappedMessage: $message = MessageTransformer::getWrappedMessage($message); break; case $message: throw new MailWrapperSetupException('Unknown Message'); default: break; } return new self($message); }
/** * */ public function testTransformToWrappedMessage() { $message = new MailWrappedMessage(); $newMessage = MessageTransformer::getWrappedMessage($message); $this->assertInstanceOf('BespokeSupport\\MailWrapper\\MailWrappedMessage', $newMessage); }
/** * */ public function testConvert() { $message = TesterMessageZend::getValid(); $newMessage = MessageTransformer::convert($message, 'zend'); $this->assertInstanceOf('Zend\\Mail\\Message', $newMessage); }
/** * */ public function testConvert() { $message = TesterMessagePhpMailer::getValid(); $newMessage = MessageTransformer::convert($message, 'phpmailer'); $this->assertInstanceOf('PHPMailer', $newMessage); }
/** * */ public function testConvert() { $message = TesterMessageSwift::getValid(); $newMessage = MessageTransformer::convert($message, 'swift'); $this->assertInstanceOf('\\Swift_Message', $newMessage); }