77 lines
2.6 KiB
PHP
77 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\Facades\Request;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\Facades\Vite;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ThemeServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// Registriere die domains.php Konfigurationsdatei
|
|
$this->mergeConfigFrom(
|
|
base_path('config/domains.php'),
|
|
'domains'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Bootstrap services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$host = Request::getHost(); // is domain_name
|
|
$themeOverride = Request::get('theme'); // Allow theme override via URL parameter
|
|
|
|
// Standard-Werte für Domain, die nicht in der Konfiguration sind
|
|
$domainConfig = [
|
|
'name' => config('app.name'),
|
|
'theme' => 'b2in',
|
|
'view_prefix' => 'b2in',
|
|
'assets_dir' => 'build/b2in',
|
|
'url' => config('app.url'),
|
|
'domain_name' => config('app.domain_name'),
|
|
];
|
|
|
|
// Lade die Domain-Konfiguration
|
|
$confiDomains = config('domains.domains');
|
|
|
|
// Suche nach der aktuellen Domain in der Konfiguration
|
|
foreach ($confiDomains as $name => $config) {
|
|
if (is_array($config) && isset($config['domain_name']) && $config['domain_name'] === $host) {
|
|
$domainConfig = array_merge($domainConfig, $config);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Allow theme override via URL parameter (for testing)
|
|
if ($themeOverride && isset($confiDomains[$themeOverride])) {
|
|
$domainConfig = array_merge($domainConfig, $confiDomains[$themeOverride]);
|
|
}
|
|
|
|
// Grundlegende Konfiguration im Anwendungskontext verfügbar machen
|
|
config([
|
|
'app.theme' => $domainConfig['theme'],
|
|
'app.view_prefix' => $domainConfig['view_prefix'],
|
|
'app.domain_name' => $domainConfig['domain_name'],
|
|
'app.url' => $domainConfig['url'],
|
|
]);
|
|
|
|
// Spezifischere Daten für die Views verfügbar machen
|
|
View::share('theme', $domainConfig['theme']);
|
|
View::share('viewPrefix', $domainConfig['view_prefix']);
|
|
View::share('domainName', $domainConfig['domain_name']);
|
|
View::share('domainConfig', $domainConfig);
|
|
View::share('domainUrl', $domainConfig['url']);
|
|
// Vite-Assets-Konfiguration für die aktuelle Domain
|
|
if (! app()->runningInConsole() && isset($domainConfig['assets_dir'])) {
|
|
Vite::useBuildDirectory($domainConfig['assets_dir']);
|
|
}
|
|
}
|
|
}
|