Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Fix #1: Adjust to yiisoft/mailer's changes (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored and devanych committed Dec 19, 2020
1 parent 5ffb778 commit a188fdc
Show file tree
Hide file tree
Showing 18 changed files with 850 additions and 1,127 deletions.
13 changes: 5 additions & 8 deletions .travis.yml
Expand Up @@ -17,12 +17,9 @@ install:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install --prefer-dist --no-interaction

before_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.3' ]; then
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
fi
script:
- ./vendor/bin/phpunit $PHPUNIT_FLAGS
- ./vendor/bin/phpunit $PHPUNIT_FLAGS --coverage-clover=coverage.clover

after_script:
- wget -c https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
41 changes: 14 additions & 27 deletions README.md
Expand Up @@ -6,44 +6,31 @@
<br>
</p>

This extension provides a [SwiftMailer](https://swiftmailer.symfony.com/) mail solution for [Yii framework](http://www.yiiframework.com).
This library is a [Mailer](https://github.com/yiisoft/mailer) implementation that provides a [SwiftMailer](https://swiftmailer.symfony.com/) mail solution
for [Yii framework](http://www.yiiframework.com).

For license information check the [LICENSE](LICENSE.md)-file.

[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii-swiftmailer/v/stable.png)](https://packagist.org/packages/yiisoft/yii-swiftmailer)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii-swiftmailer/downloads.png)](https://packagist.org/packages/yiisoft/yii-swiftmailer)
[![Build Status](https://travis-ci.org/yiisoft/yii-swiftmailer.svg?branch=master)](https://travis-ci.org/yiisoft/yii-swiftmailer)
[![Latest Stable Version](https://poser.pugx.org/yiisoft/mailer-swiftmailer/v/stable.png)](https://packagist.org/packages/yiisoft/mailer-swiftmailer)
[![Total Downloads](https://poser.pugx.org/yiisoft/mailer-swiftmailer/downloads.png)](https://packagist.org/packages/yiisoft/mailer-swiftmailer)
[![Build Status](https://travis-ci.org/yiisoft/mailer-swiftmailer.svg?branch=master)](https://travis-ci.org/yiisoft/mailer-swiftmailer)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/mailer-swiftmailer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/mailer-swiftmailer/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/mailer-swiftmailer/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/mailer-swiftmailer/?branch=master)

## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
The preferred way to install this library is through [composer](http://getcomposer.org/download/).

```
php composer.phar require --prefer-dist yiisoft/yii-swiftmailer
php composer.phar require --prefer-dist yiisoft/mailer-swiftmailer
```

## Usage

To use this extension, simply add the following code in your application configuration:

```php
return [
//....
'mailer' => [
'__class' => Yiisoft\Yii\SwiftMailer\Mailer::class,
],
];
$mailer->compose('contact/html')
->setFrom('from@domain.com')
->setTo('to@domain.com')
->setSubject($subject)
->send();
```

You can then send an email as follows:

```php
$app->get('mailer')->compose('contact/html')
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
```

For further instructions refer to the [related section in the Yii Definitive Guide](http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html).

24 changes: 9 additions & 15 deletions composer.json
Expand Up @@ -5,8 +5,8 @@
"type": "library",
"license": "BSD-3-Clause",
"support": {
"source": "https://github.com/yiisoft/yii-swiftmailer",
"issues": "https://github.com/yiisoft/yii-swiftmailer/issues",
"source": "https://github.com/yiisoft/mailer-swiftmailer",
"issues": "https://github.com/yiisoft/mailer-swiftmailer/issues",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii"
Expand All @@ -20,31 +20,25 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"yiisoft/arrays": "^3.0@dev",
"yiisoft/yii-core": "^3.0@dev",
"swiftmailer/swiftmailer": "~6.0"
"php": "^7.2",
"swiftmailer/swiftmailer": "~6.0",
"yiisoft/mailer": "^3.0@dev"
},
"require-dev": {
"phpunit/phpunit": "^7.3",
"hiqdev/composer-config-plugin": "^1.0@dev",
"yiisoft/di": "^3.0@dev",
"yiisoft/log": "^3.0@dev",
"yiisoft/cache": "^3.0@dev",
"yiisoft/yii-web": "^3.0@dev"
"yiisoft/event-dispatcher": "^3.0@dev",
"yiisoft/log": "^3.0@dev"
},
"autoload": {
"psr-4": {"Yiisoft\\Yii\\SwiftMailer\\": "src"}
"psr-4": {"Yiisoft\\Mailer\\SwiftMailer\\": "src"}
},
"autoload-dev": {
"psr-4": {"Yiisoft\\Yii\\SwiftMailer\\Tests\\": "tests"}
"psr-4": {"Yiisoft\\Mailer\\SwiftMailer\\Tests\\": "tests"}
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
},
"config-plugin": {
"common": "config/common.php",
"tests": "config/tests.php"
}
}
}
7 changes: 0 additions & 7 deletions config/common.php

This file was deleted.

9 changes: 0 additions & 9 deletions config/tests.php

This file was deleted.

34 changes: 22 additions & 12 deletions phpunit.xml.dist
@@ -1,14 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Yii2-swiftmailer Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Yii2-swiftmailer Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
73 changes: 15 additions & 58 deletions src/Logger.php
@@ -1,63 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace Yiisoft\Mailer\SwiftMailer;

namespace Yiisoft\Yii\SwiftMailer;

use Psr\Log\LogLevel;
use yii\helpers\Yii;
use Psr\Log\{LoggerInterface, LogLevel};

/**
* Logger is a SwiftMailer plugin, which allows passing of the SwiftMailer internal logs to the
* Yii logging mechanism. Each native SwiftMailer log message will be converted into Yii 'info' log entry.
*
* This logger will be automatically created and applied to underlying [[\Swift_Mailer]] instance, if [[Mailer::$enableSwiftMailerLogging]]
* is enabled. For example:
*
* ```php
* [
* 'components' => [
* 'mailer' => [
* '__class' => Yiisoft\Yii\SwiftMailer\Mailer::class,
* 'enableSwiftMailerLogging' => true,
* ],
* ],
* // ...
* ],
* ```
*
*
* In order to catch logs written by this class, you need to setup a log route for 'Yiisoft\Yii\SwiftMailer\Logger::add' category.
* For example:
*
* ```php
* [
* 'components' => [
* 'log' => [
* 'targets' => [
* [
* '__class' => Yiisoft\Log\FileTarget::class,
* 'categories' => ['Yiisoft\Yii\SwiftMailer\Logger::add'],
* ],
* ],
* ],
* // ...
* ],
* // ...
* ],
* ```
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0.4
* Logger is a PSR-3 logger plugin for SwiftMailer.
*/
class Logger implements \Swift_Plugins_Logger
{
/**
* {@inheritdoc}
* @var LoggerInterface $logger logger instance.
*/
private $psrLogger;

/**
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $psrLogger)
{
$this->psrLogger = $psrLogger;
}

public function add($entry)
{
$categoryPrefix = substr($entry, 0, 2);
Expand All @@ -76,20 +39,14 @@ public function add($entry)
$level = LogLevel::INFO;
}

Yii::log($level, $entry, ['category' => __METHOD__]);
$this->psrLogger->log($level, $entry, ['category' => __METHOD__]);
}

/**
* {@inheritdoc}
*/
public function clear()
{
// do nothing
}

/**
* {@inheritdoc}
*/
public function dump()
{
return '';
Expand Down

0 comments on commit a188fdc

Please sign in to comment.