Skip to content

Commit

Permalink
Fix #50: Forward transport logs to the Yii Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa authored Feb 17, 2023
1 parent e26ce9c commit a244f0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ jobs:
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.php }}-
- name: Install dependencies
run: composer update $DEFAULT_COMPOSER_FLAGS
- name: Install logging proxy
if: ${{ matrix.php != '7.4' }}
run: composer require "yiisoft/yii2-psr-log-source"
- name: Run unit tests with coverage
run: vendor/bin/phpunit --coverage-text
- name: Static analysis (Psalm)
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Yii Framework 2 Symfony mailer extension Change Log
================================================

3.0.1 under development
3.1.0 under development
-----------------------

- Enh #45: Added option to create transport from Dsn object (Swanty)
- Enh #50: Forward transport logs to the Yii Logger (sammousa)


3.0.0 December 05, 2022
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"captainhook/captainhook": "^5.10",
"captainhook/plugin-composer": "^5.3"
},
"suggest": {
"yiisoft/yii2-psr-log-source": "Allows routing transport logs to your Yii2 logger"
},
"repositories": [
{
"type": "composer",
Expand Down
10 changes: 9 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace yii\symfonymailer;

use Psr\Log\LoggerInterface;
use Symfony\Component\Mailer\Mailer as SymfonyMailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mailer\Transport\Dsn;
Expand All @@ -16,6 +17,8 @@
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\mail\BaseMailer;
use yii\psr\DynamicLogger;
use yii\psr\Logger;

/**
* @psalm-suppress PropertyNotSetInConstructor
Expand Down Expand Up @@ -93,7 +96,12 @@ private function getTransportFactory(): Transport
if (isset($this->transportFactory)) {
return $this->transportFactory;
}
$defaultFactories = Transport::getDefaultFactories();
/** @var LoggerInterface|null $logger */
$logger = class_exists(DynamicLogger::class) ? new DynamicLogger() : null;
/**
* @psalm-suppress TooManyArguments On PHP 7.4 symfony/mailer 5.4 is uses which uses func_get_args instead of real args
*/
$defaultFactories = Transport::getDefaultFactories(null, null, $logger);
/** @psalm-suppress InvalidArgument Symfony's type annotation is wrong */
return new Transport($defaultFactories);
}
Expand Down

0 comments on commit a244f0d

Please sign in to comment.