1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 20:34:03 +00:00

Depend less on the default mailer by adding a static $mailer property

This commit is contained in:
lukinovec 2022-11-03 08:28:00 +01:00
parent 635b299950
commit 55aa49b18e

View file

@ -10,8 +10,6 @@ use Stancl\Tenancy\Contracts\Tenant;
class MailTenancyBootstrapper implements TenancyBootstrapper class MailTenancyBootstrapper implements TenancyBootstrapper
{ {
protected array $originalConfig = [];
/** /**
* Tenant properties to be mapped to config (similarly to the TenantConfig feature). * Tenant properties to be mapped to config (similarly to the TenantConfig feature).
* *
@ -22,7 +20,11 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
*/ */
public static array $credentialsMap = []; public static array $credentialsMap = [];
public static function smtpCredentialsMap(): array public static string|null $mailer = null;
protected array $originalConfig = [];
public static function smtpPreset(): array
{ {
return [ return [
'mail.mailers.smtp.host' => 'smtp_host', 'mail.mailers.smtp.host' => 'smtp_host',
@ -34,13 +36,14 @@ class MailTenancyBootstrapper implements TenancyBootstrapper
public function __construct(protected Repository $config) public function __construct(protected Repository $config)
{ {
static::$mailer ??= $config->get('mail.default');
static::$credentialsMap = array_merge(static::$credentialsMap, $this->pickMapPreset() ?? []); static::$credentialsMap = array_merge(static::$credentialsMap, $this->pickMapPreset() ?? []);
} }
protected function pickMapPreset(): array|null protected function pickMapPreset(): array|null
{ {
return match ($this->config->get('mail.default')) { return match (static::$mailer) {
'smtp' => static::smtpCredentialsMap(), 'smtp' => static::smtpPreset(),
default => null, default => null,
}; };
} }