111 lines
4.1 KiB
PHP
111 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Domain\DomainContext;
|
|
use App\Services\DomainService;
|
|
use App\Services\UserShopSessionManager;
|
|
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
/**
|
|
* Optimierter Domain-Service-Provider für GPT-5 v3.1
|
|
*
|
|
* Ersetzt den ursprünglichen DomainServiceProvider und registriert
|
|
* die neuen optimierten Services ohne die problematische Middleware-Registrierung.
|
|
*/
|
|
class DomainServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Registriert die Domain-Services im Container
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// 1. DomainService als Singleton (vom ursprünglichen Provider übernommen)
|
|
$this->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'
|
|
]);
|
|
}
|
|
}
|
|
}
|