From 91208fd0a21bcaec2abf0b95e0e6bec4ff0aaa08 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 14 Feb 2023 16:51:17 +0100 Subject: [PATCH 1/5] feat: send transport logs to Yii logger, if available --- composer.json | 11 ++++++++++- src/Mailer.php | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f54ece8..e765d04 100644 --- a/composer.json +++ b/composer.json @@ -34,14 +34,23 @@ "symplify/easy-coding-standard": "^10.1", "vimeo/psalm": "^4.22", "captainhook/captainhook": "^5.10", - "captainhook/plugin-composer": "^5.3" + "captainhook/plugin-composer": "^5.3", + "yiisoft/yii2-psr-log-source": "dev-feat-dynamic-logger" + }, + "suggest": { + "yiisoft/yii2-psr-log-source": "Allows routing transport logs to your Yii2 logger" }, "repositories": [ { "type": "composer", "url": "https://asset-packagist.org" + }, + { + "type": "vcs", + "url": "https://github.com/SamMousa/yii2-psr-log-source" } ], + "autoload": { "psr-4": { "yii\\symfonymailer\\": "src" diff --git a/src/Mailer.php b/src/Mailer.php index 80f35de..19d1c47 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -16,6 +16,8 @@ use yii\base\InvalidArgumentException; use yii\base\InvalidConfigException; use yii\mail\BaseMailer; +use yii\psr\DynamicLogger; +use yii\psr\Logger; /** * @psalm-suppress PropertyNotSetInConstructor @@ -93,7 +95,8 @@ private function getTransportFactory(): Transport if (isset($this->transportFactory)) { return $this->transportFactory; } - $defaultFactories = Transport::getDefaultFactories(); + $logger = class_exists(DynamicLogger::class) ? new DynamicLogger() : null; + $defaultFactories = Transport::getDefaultFactories(null, null, $logger); /** @psalm-suppress InvalidArgument Symfony's type annotation is wrong */ return new Transport($defaultFactories); } From 160e74ce505856ee0ebc147545551d426df43c05 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 14 Feb 2023 16:58:38 +0100 Subject: [PATCH 2/5] fix: remove logging proxy from dev dependency to allow php7.4 build --- composer.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/composer.json b/composer.json index e765d04..8997137 100644 --- a/composer.json +++ b/composer.json @@ -34,8 +34,7 @@ "symplify/easy-coding-standard": "^10.1", "vimeo/psalm": "^4.22", "captainhook/captainhook": "^5.10", - "captainhook/plugin-composer": "^5.3", - "yiisoft/yii2-psr-log-source": "dev-feat-dynamic-logger" + "captainhook/plugin-composer": "^5.3" }, "suggest": { "yiisoft/yii2-psr-log-source": "Allows routing transport logs to your Yii2 logger" @@ -44,13 +43,8 @@ { "type": "composer", "url": "https://asset-packagist.org" - }, - { - "type": "vcs", - "url": "https://github.com/SamMousa/yii2-psr-log-source" } ], - "autoload": { "psr-4": { "yii\\symfonymailer\\": "src" From f540944033d494c1dc43b2ec032dae3a941f3106 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 14 Feb 2023 17:15:28 +0100 Subject: [PATCH 3/5] ci: install logger proxy in ci if not on php 7.4 --- .github/workflows/build.yml | 7 +++++-- src/Mailer.php | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8c25a3..1cd306b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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) diff --git a/src/Mailer.php b/src/Mailer.php index 19d1c47..3232f87 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -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; @@ -95,6 +96,7 @@ private function getTransportFactory(): Transport if (isset($this->transportFactory)) { return $this->transportFactory; } + /** @var LoggerInterface|null $logger */ $logger = class_exists(DynamicLogger::class) ? new DynamicLogger() : null; $defaultFactories = Transport::getDefaultFactories(null, null, $logger); /** @psalm-suppress InvalidArgument Symfony's type annotation is wrong */ From 933d6d6b2e1105d1c4df44974d0ccc090b61a3b6 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 14 Feb 2023 17:26:05 +0100 Subject: [PATCH 4/5] fix: static analysis fails on php 7.4 --- src/Mailer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Mailer.php b/src/Mailer.php index 3232f87..1e23542 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -98,6 +98,9 @@ private function getTransportFactory(): Transport } /** @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); From 93ae4e8a43f47f85da0e1ee2a4de024b6f519a35 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Wed, 15 Feb 2023 10:01:53 +0100 Subject: [PATCH 5/5] chore: update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a0d23b..12c3648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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