app->singleton(DomainService::class, function ($app) { $domainService = new DomainService($app['config']['domains']); // Validiere Konfiguration in der Development-Umgebung if (config('app.debug')) { $configErrors = $domainService->validateConfiguration(); if (!empty($configErrors)) { \Log::channel('domain')->warning('Domain configuration errors detected', ['errors' => $configErrors]); } } return $domainService; }); // 2. DomainContext als Singleton registrieren. // Die Logik hier wird nur einmal pro Anfrage ausgeführt (lazy-loaded), // wenn der Context das erste Mal benötigt wird. Das ist effizient und korrekt. $this->app->singleton(DomainContext::class, function ($app) { /** @var DomainService $domainService */ $domainService = $app->make(DomainService::class); $request = $app->make('request'); // Analysiere den Host der aktuellen Anfrage $domainInfo = $domainService->parseDomain($request->getHost()); $userShop = null; // Wenn es sich um eine User-Shop-Domain handelt, versuche das Shop-Objekt zu finden. if ($domainInfo['type'] === 'user-shop' && $domainInfo['subdomain']) { $userShop = $domainService->getUserShop($domainInfo['subdomain']); // Wenn der Shop ungültig ist, wird der Typ auf 'unknown' gesetzt. if (!$userShop) { $domainInfo['type'] = 'unknown'; } } // Wenn es sich um die Haupt-Shop-Domain handelt (z.B. mivita.shop), // lade den konfigurierten Fallback-Shop. if ($domainInfo['type'] === 'main-shop' && !empty($domainInfo['default_user_shop'])) { $userShop = $domainService->getUserShop($domainInfo['default_user_shop']); } return DomainContext::fromArray($domainInfo, $userShop); }); } /** * Führt Aktionen nach der Registrierung aller Provider aus. * * @return void */ public function boot() { // Die Middleware-Registrierung wird von hier entfernt. // $kernel = $this->app->make(\Illuminate\Contracts\Http\Kernel::class); // $kernel->prependMiddlewareToGroup('web', DomainResolver::class); } }