mailwolt/app/Providers/AppServiceProvider.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Providers;
use App\Support\SettingsRepository;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton(SettingsRepository::class, fn() => new SettingsRepository());
}
/**
* Bootstrap any application services.
*/
public function boot(SettingsRepository $settings): void
{
try {
$S = app(\App\Support\SettingsRepository::class);
if ($tz = $S->get('app.timezone')) {
config(['app.timezone' => $tz]);
date_default_timezone_set($tz);
}
if ($domain = $S->get('app.domain')) {
// Falls du APP_URL dynamisch überschreiben willst:
$scheme = $S->get('app.force_https', true) ? 'https' : 'http';
config(['app.url' => $scheme.'://'.$domain]);
URL::forceRootUrl(config('app.url'));
if ($scheme === 'https') {
URL::forceScheme('https');
}
}
} catch (\Throwable $e) {
// Im Bootstrap/Wartungsmodus still sein
}
}
}