refactor(configuration): centralize configuration management in ConfigurationRepository
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
use App\Services\ConfigurationRepository;
|
||||
use Exception;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -9,6 +10,13 @@ use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class EmailChannel
|
||||
{
|
||||
private ConfigurationRepository $configRepository;
|
||||
|
||||
public function __construct(ConfigurationRepository $configRepository)
|
||||
{
|
||||
$this->configRepository = $configRepository;
|
||||
}
|
||||
|
||||
public function send(SendsEmail $notifiable, Notification $notification): void
|
||||
{
|
||||
try {
|
||||
@@ -57,34 +65,6 @@ class EmailChannel
|
||||
return;
|
||||
}
|
||||
|
||||
config()->set('mail.from.address', $emailSettings->smtp_from_address ?? 'test@example.com');
|
||||
config()->set('mail.from.name', $emailSettings->smtp_from_name ?? 'Test');
|
||||
|
||||
if ($emailSettings->resend_enabled) {
|
||||
config()->set('mail.default', 'resend');
|
||||
config()->set('resend.api_key', $emailSettings->resend_api_key);
|
||||
}
|
||||
|
||||
if ($emailSettings->smtp_enabled) {
|
||||
$encryption = match (strtolower($emailSettings->smtp_encryption)) {
|
||||
'starttls' => null,
|
||||
'tls' => 'tls',
|
||||
'none' => null,
|
||||
default => null,
|
||||
};
|
||||
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
'transport' => 'smtp',
|
||||
'host' => $emailSettings->smtp_host,
|
||||
'port' => $emailSettings->smtp_port,
|
||||
'encryption' => $encryption,
|
||||
'username' => $emailSettings->smtp_username,
|
||||
'password' => $emailSettings->smtp_password,
|
||||
'timeout' => $emailSettings->smtp_timeout,
|
||||
'local_domain' => null,
|
||||
'auto_tls' => $emailSettings->smtp_encryption === 'none' ? '0' : '', // If encryption is "none", it will not try to upgrade to TLS via StartTLS to make sure it is unencrypted.
|
||||
]);
|
||||
}
|
||||
$this->configRepository->updateMailConfig($emailSettings);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user