92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Domain;
|
|
use App\Observers\DomainObserver;
|
|
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(\App\Support\SettingsRepository $settings): void
|
|
{
|
|
Domain::observe(DomainObserver::class);
|
|
|
|
config(['app.version' => trim(@file_get_contents('/var/lib/mailwolt/version')) ?: 'dev']);
|
|
if (file_exists(base_path('.git/HEAD'))) {
|
|
$ref = trim(file_get_contents(base_path('.git/HEAD')));
|
|
if (str_starts_with($ref, 'ref:')) {
|
|
$refFile = base_path('.git/' . substr($ref, 5));
|
|
$commit = @file_get_contents($refFile);
|
|
} else {
|
|
$commit = $ref;
|
|
}
|
|
|
|
config(['app.git_commit' => substr($commit ?? '', 0, 7)]);
|
|
}
|
|
|
|
try {
|
|
$S = app(\App\Support\SettingsRepository::class);
|
|
|
|
// 🕒 Zeitzone
|
|
if ($tz = $S->get('system.timezone')) {
|
|
config(['app.timezone' => $tz]);
|
|
date_default_timezone_set($tz);
|
|
}
|
|
|
|
// 🌐 Sprache
|
|
if ($locale = $S->get('system.locale')) {
|
|
app()->setLocale($locale);
|
|
}
|
|
|
|
// 🌍 Domain / URL
|
|
if ($domain = $S->get('app.domain')) {
|
|
$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) {
|
|
// Keine Exceptions beim Booten, z. B. wenn DB oder Redis noch nicht erreichbar sind
|
|
// \Log::warning('settings.boot_failed', ['msg' => $e->getMessage()]);
|
|
}
|
|
}
|
|
// 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
|
|
// }
|
|
// }
|
|
}
|