Files
portal-api/app/Providers/MailConfigServiceProvider.php
T
baodev0 dfb926055d Add feature tests for domain order management
- Implement AdminDomainOrderTest to cover admin functionalities for domain orders including listing, confirming registration, KYC updates, activation, rejection, and refunds.
- Implement ClientDomainOrderTest to cover client functionalities for placing domain orders, including validation for balance, duplicate orders, and domain normalization.
- Ensure proper handling of domain pricing and service statuses throughout the tests.
2026-07-10 14:16:35 +07:00

86 lines
2.5 KiB
PHP

<?php
namespace App\Providers;
use App\Http\Services\SignRSA;
use App\Models\Setting;
use App\Support\Cache\CacheKey;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class MailConfigServiceProvider extends ServiceProvider
{
private static ?array $resolved = null;
public function register()
{
//
}
public function boot()
{
if (App::runningInConsole()) {
return;
}
if (self::$resolved !== null) {
Config::set('mail', self::$resolved);
return;
}
$config = Cache::remember(CacheKey::build('settings', 'mail'), 3600, function () {
if (!Schema::hasTable('setting')) {
return null;
}
$mail = Setting::where('key', 'smtp')->first();
$setting = Setting::where('key', 'setting')->first();
if (!$mail || !$setting) {
return null;
}
$mail = json_decode($mail->value);
$company = json_decode($setting->value)->company ?? 'Your Company';
$password = '';
if (isset($mail->password)) {
$decrypted = (new SignRSA())->DecryptFunc($mail->password);
$password = $decrypted ?: $mail->password;
}
$transport = $mail->transport ?? 'smtp';
$encryption = $mail->encryption ?? config('mail.mailers.smtp.encryption');
if ($encryption === 0 || $encryption === '0' || $encryption === 'starttls') {
$encryption = 'tls';
}
$config = config('mail');
$config['default'] = $transport;
$config['from'] = [
'address' => $mail->user ?? config('mail.from.address', 'no-reply@example.com'),
'name' => $company,
];
$config['mailers'][$transport] = array_merge($config['mailers'][$transport] ?? [], [
'transport' => $transport,
'host' => $mail->host ?? '',
'port' => $mail->port ?? 587,
'encryption' => $encryption,
'username' => $mail->user ?? '',
'password' => $password,
]);
return $config;
});
if ($config) {
self::$resolved = $config;
Config::set('mail', $config);
}
}
}