From 62c8bb0f67c7d5fd49f08ec6b88bfc154500a8f9 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 31 Oct 2022 15:01:58 +0100 Subject: [PATCH] Replace MailManager singleton with an instance of a custom mail manager which always resolves the mailers instead of getting the cached ones --- src/TenancyMailManager.php | 15 +++++++++++++++ src/TenancyServiceProvider.php | 16 +++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/TenancyMailManager.php diff --git a/src/TenancyMailManager.php b/src/TenancyMailManager.php new file mode 100644 index 00000000..7feee4fa --- /dev/null +++ b/src/TenancyMailManager.php @@ -0,0 +1,15 @@ +resolve($name); + } +} diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 01770cda..0dfc7509 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -4,16 +4,17 @@ declare(strict_types=1); namespace Stancl\Tenancy; +use Illuminate\Mail\MailManager; +use Stancl\Tenancy\Enums\LogMode; use Illuminate\Cache\CacheManager; -use Illuminate\Database\Console\Migrations\FreshCommand; -use Illuminate\Support\Facades\Event; -use Illuminate\Support\ServiceProvider; -use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; use Stancl\Tenancy\Contracts\Domain; use Stancl\Tenancy\Contracts\Tenant; -use Stancl\Tenancy\Enums\LogMode; +use Illuminate\Support\Facades\Event; +use Illuminate\Support\ServiceProvider; use Stancl\Tenancy\Events\Contracts\TenancyEvent; use Stancl\Tenancy\Resolvers\DomainTenantResolver; +use Illuminate\Database\Console\Migrations\FreshCommand; +use Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper; class TenancyServiceProvider extends ServiceProvider { @@ -69,6 +70,11 @@ class TenancyServiceProvider extends ServiceProvider return new Commands\Seed($app['db']); }); + // Use custom mail manager that resolves the mailers instead of getting the cached mailers from the $mailers property + $this->app->extend(MailManager::class, function (MailManager $mailManager) { + return new TenancyMailManager($this->app); + }); + $this->app->bind('globalCache', function ($app) { return new CacheManager($app); });