- Created stubs for JavaScript and SASS assets. - Added stubs for channel, command, component, controller, event, factory, job, listener, mail, middleware, migration, model, notification, observer, policy, request, resource, route provider, seeder, and validation rule. - Implemented scaffolding for configuration, service provider, and Vite integration. - Included example views for module structure. - Introduced a module loader for Vite to handle asset paths dynamically.
75 lines
2.1 KiB
PHP
75 lines
2.1 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;
|
|
}
|
|
|
|
return [
|
|
'driver' => $mail->transport ?? 'smtp',
|
|
'host' => $mail->host ?? '',
|
|
'port' => $mail->port ?? 587,
|
|
'from' => [
|
|
'address' => $mail->user ?? 'no-reply@example.com',
|
|
'name' => $company,
|
|
],
|
|
'encryption' => $mail->encryption === 0 ? 'tls' : $mail->encryption,
|
|
'username' => $mail->user ?? '',
|
|
'password' => $password,
|
|
];
|
|
});
|
|
|
|
if ($config) {
|
|
self::$resolved = $config;
|
|
Config::set('mail', $config);
|
|
}
|
|
}
|
|
}
|