mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:34:04 +00:00
Move MailManager extension to MailTenancyBootstrapper
This commit is contained in:
parent
d5e0e34087
commit
d83cd1ddb4
3 changed files with 13 additions and 8 deletions
|
|
@ -4,9 +4,12 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
|
use Illuminate\Mail\MailManager;
|
||||||
use Illuminate\Config\Repository;
|
use Illuminate\Config\Repository;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Stancl\Tenancy\TenancyMailManager;
|
||||||
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
||||||
class MailTenancyBootstrapper implements TenancyBootstrapper
|
class MailTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
|
|
@ -33,7 +36,7 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(protected Repository $config)
|
public function __construct(protected Repository $config, protected Application $app)
|
||||||
{
|
{
|
||||||
static::$mailer ??= $config->get('mail.default');
|
static::$mailer ??= $config->get('mail.default');
|
||||||
static::$credentialsMap = array_merge(static::$credentialsMap, static::$mapPresets[static::$mailer] ?? []);
|
static::$credentialsMap = array_merge(static::$credentialsMap, static::$mapPresets[static::$mailer] ?? []);
|
||||||
|
|
@ -41,6 +44,12 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant): void
|
public function bootstrap(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
|
// Use custom mail manager that resolves the mailers specified in its $tenantMailers static property
|
||||||
|
// Instead of getting the cached mailers from the $mailers property
|
||||||
|
$this->app->extend(MailManager::class, function (MailManager $mailManager) {
|
||||||
|
return new TenancyMailManager($this->app);
|
||||||
|
});
|
||||||
|
|
||||||
$this->setConfig($tenant);
|
$this->setConfig($tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,6 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
return new Commands\Seed($app['db']);
|
return new Commands\Seed($app['db']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use custom mail manager that resolves the mailers specified in its $tenantMailers static property
|
|
||||||
// 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) {
|
$this->app->bind('globalCache', function ($app) {
|
||||||
return new CacheManager($app);
|
return new CacheManager($app);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ beforeEach(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('tenancy swaps the MailManager singleton for an instance of TenancyMailManager', function() {
|
test('tenancy swaps the MailManager singleton for an instance of TenancyMailManager', function() {
|
||||||
|
tenancy()->initialize(Tenant::create());
|
||||||
|
|
||||||
expect(app(MailManager::class))->toBeInstanceOf(TenancyMailManager::class);
|
expect(app(MailManager::class))->toBeInstanceOf(TenancyMailManager::class);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue