app->singleton(DomainService::class, function ($app) { $domainService = new DomainService($app['config']['domains']); // Validiere Konfiguration in Development 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 (vom ursprünglichen Provider übernommen) $this->app->singleton(DomainContext::class, function ($app) { /** @var DomainService $domainService */ $domainService = $app->make(DomainService::class); $request = $app->make('request'); // Domain-Info analysieren $domainInfo = $domainService->parseDomain($request->getHost()); if (config('app.debug')) { \Log::channel('domain')->debug('DomainServiceProvider: domainInfo', [ 'domainInfo' => $domainInfo, 'host' => $request->getHost() ]); } $userShop = null; // UserShop-Domains: Shop-Objekt laden if ($domainInfo['type'] === 'user-shop' && $domainInfo['subdomain']) { $userShop = $domainService->getUserShop($domainInfo['subdomain']); if (!$userShop) { $domainInfo['type'] = 'unknown'; } } // Haupt-Shop-Domain: Fallback-Shop laden (Fix: Korrekter Type-Check) if ($domainInfo['type'] === 'shop' && !empty($domainInfo['default_user_shop'])) { $userShop = $domainService->getUserShop($domainInfo['default_user_shop']); } return DomainContext::fromArray($domainInfo, $userShop); }); // 3. UserShopSessionManager registrieren (GPT-5 v3.1 neu) $this->app->singleton(UserShopSessionManager::class, function ($app) { return new UserShopSessionManager( $app->make(DomainService::class), $app->make(CookieFactory::class) ); }); } /** * Bootstrap-Aktionen (KEINE Middleware-Registrierung!) * * Im Gegensatz zum ursprünglichen DomainServiceProvider registrieren wir * KEINE Middleware hier - das passiert manuell im Kernel für bessere Kontrolle. */ public function boot(): void { // Konfiguration publishen (optional) if ($this->app->runningInConsole()) { $this->publishes([ __DIR__ . '/../../config/subdomain.php' => config_path('subdomain.php'), ], 'subdomain-config'); } // Debug-Logging für erfolgreiche Service-Registrierung if (config('app.debug')) { \Log::channel('domain')->debug('DomainServiceProvider: Services registered successfully', [ 'services' => [ 'DomainService' => DomainService::class, 'DomainContext' => DomainContext::class, 'UserShopSessionManager' => UserShopSessionManager::class, ], 'note' => 'Middleware must be registered manually in Http/Kernel.php' ]); } } }