diff --git a/composer.json b/composer.json index 8e3a7c61b..b4d959ce6 100755 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "MIT", "require": { "php" : ">=5.3.0", - "swiftmailer/swiftmailer": "~5.2" + "swiftmailer/swiftmailer": "~5.2|~6.0" }, "require-dev": { "psr/log": "*" diff --git a/lib/mailer/sfMailer.class.php b/lib/mailer/sfMailer.class.php old mode 100755 new mode 100644 index ee9ce93e8..8805b41c4 --- a/lib/mailer/sfMailer.class.php +++ b/lib/mailer/sfMailer.class.php @@ -1,12 +1,92 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ +// Defining a base class for sfMailer to handle both, Swiftmailer 5 and Swiftmailer 6. +if(class_exists('Swift') && version_compare(Swift::VERSION, '6.0.0') >= 0) { + class sfMailerBase extends Swift_Mailer + { + /** + * Sends the given message. + * + * @param Swift_Mime_SimpleMessage $message A transport instance + * @param string[] &$failedRecipients An array of failures by-reference + * + * @return int|false The number of sent emails + */ + public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) + { + if ($this->force) + { + $this->force = false; + + if (!$this->realtimeTransport->isStarted()) + { + $this->realtimeTransport->start(); + } + + return $this->realtimeTransport->send($message, $failedRecipients); + } + + return parent::send($message, $failedRecipients); + } + + /** + * @inheritDoc + */ + public function compose($from = null, $to = null, $subject = null, $body = null) + { + $msg = new Swift_Message($subject); + + return $msg + ->setFrom($from) + ->setTo($to) + ->setBody($body) + ; + } + } +} else { + class sfMailerBase extends Swift_Mailer + { + /** + * Sends the given message. + * + * @param Swift_Mime_Message $message A transport instance + * @param string[] &$failedRecipients An array of failures by-reference + * + * @return int|false The number of sent emails + */ + public function send(Swift_Mime_Message $message, &$failedRecipients = null) + { + if ($this->force) + { + $this->force = false; + + if (!$this->realtimeTransport->isStarted()) + { + $this->realtimeTransport->start(); + } + + return $this->realtimeTransport->send($message, $failedRecipients); + } + + return parent::send($message, $failedRecipients); + } + + + /** + * @inheritDoc + */ + public function compose($from = null, $to = null, $subject = null, $body = null) + { + $msg = Swift_Message::newInstance($subject); + + return $msg + ->setFrom($from) + ->setTo($to) + ->setBody($body) + ; + } + } +} /** * sfMailer is the main entry point for the mailer system. @@ -18,7 +98,7 @@ * @author Fabien Potencier * @version SVN: $Id$ */ -class sfMailer extends Swift_Mailer +class sfMailer extends sfMailerBase { const REALTIME = 'realtime', @@ -63,7 +143,7 @@ public function __construct(sfEventDispatcher $dispatcher, $options) 'transport' => array( 'class' => 'Swift_MailTransport', 'param' => array(), - ), + ), ), $options); $constantName = 'sfMailer::'.strtoupper($options['delivery_strategy']); @@ -227,26 +307,6 @@ public function setDeliveryAddress($address) } } - /** - * Creates a new message. - * - * @param string|array $from The from address - * @param string|array $to The recipient(s) - * @param string $subject The subject - * @param string $body The body - * - * @return Swift_Message A Swift_Message instance - */ - public function compose($from = null, $to = null, $subject = null, $body = null) - { - return Swift_Message::newInstance() - ->setFrom($from) - ->setTo($to) - ->setSubject($subject) - ->setBody($body) - ; - } - /** * Sends a message. * @@ -274,31 +334,6 @@ public function sendNextImmediately() return $this; } - /** - * Sends the given message. - * - * @param Swift_Transport $transport A transport instance - * @param string[] &$failedRecipients An array of failures by-reference - * - * @return int|false The number of sent emails - */ - public function send(Swift_Mime_Message $message, &$failedRecipients = null) - { - if ($this->force) - { - $this->force = false; - - if (!$this->realtimeTransport->isStarted()) - { - $this->realtimeTransport->start(); - } - - return $this->realtimeTransport->send($message, $failedRecipients); - } - - return parent::send($message, $failedRecipients); - } - /** * Sends the current messages in the spool. * diff --git a/lib/vendor/swiftmailer b/lib/vendor/swiftmailer deleted file mode 160000 index 4cc928420..000000000 --- a/lib/vendor/swiftmailer +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4cc92842069c2bbc1f28daaaf1d2576ec4dfe153