Browse Source

Added support for SwiftMailer 6.0.x (#53)

tags/2.1.0
Paul Klimov 8 years ago committed by GitHub
parent
commit
3878a9ba9c
  1. 4
      .github/ISSUE_TEMPLATE.md
  2. 5
      .travis.yml
  3. 4
      CHANGELOG.md
  4. 9
      Mailer.php
  5. 4
      Message.php
  6. 2
      README.md
  7. 19
      UPGRADE.md
  8. 2
      composer.json
  9. 2
      tests/MailerTest.php
  10. 2
      tests/bootstrap.php
  11. 16
      tests/compatibility.php

4
.github/ISSUE_TEMPLATE.md

@ -8,7 +8,9 @@
### Additional info
| Q | A
| ---------------- | ---
| ----------------------- | ---
| Yii version |
| Yii SwiftMailer version |
| SwiftMailer version |
| PHP version |
| Operating system |

5
.travis.yml

@ -1,11 +1,8 @@
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1
# faster builds on new travis setup not using sudo
sudo: false

4
CHANGELOG.md

@ -1,10 +1,10 @@
Yii Framework 2 swiftmailer extension Change Log
================================================
2.0.8 under development
2.1.0 under development
-----------------------
- no changes in this release.
- Enh #31: Added support for SwiftMailer 6.0.x (klimov-paul)
2.0.7 May 01, 2017

9
Mailer.php

@ -37,7 +37,7 @@ use yii\mail\BaseMailer;
* ```
*
* You may also skip the configuration of the [[transport]] property. In that case, the default
* PHP `mail()` function will be used to send emails.
* `\Swift_SendmailTransport` transport will be used to send emails.
*
* You specify the transport constructor arguments using 'constructArgs' key in the config.
* You can also specify the list of plugins, which should be registered to the transport using
@ -140,6 +140,7 @@ class Mailer extends BaseMailer
*/
protected function sendMessage($message)
{
/* @var $message Message */
$address = $message->getTo();
if (is_array($address)) {
$address = implode(', ', array_keys($address));
@ -155,7 +156,7 @@ class Mailer extends BaseMailer
*/
protected function createSwiftMailer()
{
return \Swift_Mailer::newInstance($this->getTransport());
return new \Swift_Mailer($this->getTransport());
}
/**
@ -167,7 +168,7 @@ class Mailer extends BaseMailer
protected function createTransport(array $config)
{
if (!isset($config['class'])) {
$config['class'] = 'Swift_MailTransport';
$config['class'] = 'Swift_SendmailTransport';
}
if (isset($config['plugins'])) {
$plugins = $config['plugins'];
@ -187,7 +188,7 @@ class Mailer extends BaseMailer
];
}
/* @var $transport \Swift_MailTransport */
/* @var $transport \Swift_Transport */
$transport = $this->createSwiftObject($config);
if (!empty($plugins)) {
foreach ($plugins as $plugin) {

4
Message.php

@ -283,7 +283,7 @@ class Message extends BaseMessage
*/
public function attachContent($content, array $options = [])
{
$attachment = \Swift_Attachment::newInstance($content);
$attachment = new \Swift_Attachment($content);
if (!empty($options['fileName'])) {
$attachment->setFilename($options['fileName']);
}
@ -316,7 +316,7 @@ class Message extends BaseMessage
*/
public function embedContent($content, array $options = [])
{
$embedFile = \Swift_EmbeddedFile::newInstance($content);
$embedFile = new \Swift_EmbeddedFile($content);
if (!empty($options['fileName'])) {
$embedFile->setFilename($options['fileName']);
}

2
README.md

@ -23,7 +23,7 @@ php composer.phar require --prefer-dist yiisoft/yii2-swiftmailer
or add
```json
"yiisoft/yii2-swiftmailer": "~2.0.0"
"yiisoft/yii2-swiftmailer": "~2.1.0"
```
to the require section of your composer.json.

19
UPGRADE.md

@ -0,0 +1,19 @@
Upgrading Instructions for Yii Framework v2
===========================================
!!!IMPORTANT!!!
The following upgrading instructions are cumulative. That is,
if you want to upgrade from version A to version C and there is
version B between A and C, you need to following the instructions
for both A and B.
Upgrade from Yii 2.0.7
----------------------
* Minimal required version of the [swiftmailer/swiftmailer](https://github.com/swiftmailer/swiftmailer) library has been raised to 6.0.0.
You should adjust your program according to the [change list](https://github.com/swiftmailer/swiftmailer/blob/v6.0.0/CHANGES#L4-L17) for this version.
* Since `Swift_MailTransport` has been removed in SwiftMailer 6.0.0, this extension now uses `Swift_SendmailTransport` by default.
* Minimum version of PHP has been raised to 7.0.

2
composer.json

@ -19,7 +19,7 @@
],
"require": {
"yiisoft/yii2": "~2.0.4",
"swiftmailer/swiftmailer": "~5.0"
"swiftmailer/swiftmailer": "~6.0"
},
"autoload": {
"psr-4": { "yii\\swiftmailer\\": "" }

2
tests/MailerTest.php

@ -34,7 +34,7 @@ class MailerTest extends TestCase
{
$mailer = new Mailer();
$transport = \Swift_MailTransport::newInstance();
$transport = new \Swift_SendmailTransport();
$mailer->setTransport($transport);
$this->assertEquals($transport, $mailer->getTransport(), 'Unable to setup transport!');
}

2
tests/bootstrap.php

@ -13,5 +13,3 @@ require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
Yii::setAlias('@yiiunit/extensions/swiftmailer', __DIR__);
Yii::setAlias('@yii/swiftmailer', dirname(__DIR__));
require_once(__DIR__ . '/compatibility.php');

16
tests/compatibility.php

@ -1,16 +0,0 @@
<?php
/*
* Ensures compatibility with PHPUnit < 6.x
*/
namespace PHPUnit\Framework\Constraint {
if (!class_exists('PHPUnit\Framework\Constraint\Constraint') && class_exists('PHPUnit_Framework_Constraint')) {
abstract class Constraint extends \PHPUnit_Framework_Constraint {}
}
}
namespace PHPUnit\Framework {
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
abstract class TestCase extends \PHPUnit_Framework_TestCase {}
}
}
Loading…
Cancel
Save