update 20.10.2025

This commit is contained in:
Kevin Adametz 2025-10-20 17:42:08 +02:00
parent 8c11130b5d
commit a939cd51ef
616 changed files with 84821 additions and 4121 deletions

View file

@ -22,18 +22,20 @@ class AppServiceProvider extends ServiceProvider
}
// Domain-bewusster View Composer für user_shop
// HOTFIX: DomainContext temporär deaktiviert
// TODO: Nach Claude v2 Implementation wieder aktivieren
\View::composer('*', function ($view) {
try {
$context = app(\App\Domain\DomainContext::class);
// Für die Main-Domain: user_shop immer auf null setzen
if ($context->type === 'main') {
$view->with('user_shop', null);
} else {
// Für alle anderen Domains: normales Verhalten
$userShop = $context->userShop ?? \App\Services\Util::getUserShop();
$view->with('user_shop', $userShop);
}
// $context = app(\App\Domain\DomainContext::class);
// if ($context->type === 'main') {
// $view->with('user_shop', null);
// } else {
// $userShop = $context->userShop ?? \App\Services\Util::getUserShop();
// $view->with('user_shop', $userShop);
// }
// Temporär: Verwende immer das normale Verhalten
$view->with('user_shop', \App\Services\Util::getUserShop());
} catch (\Exception $e) {
// Fallback bei Fehlern
$view->with('user_shop', \App\Services\Util::getUserShop());

View file

@ -1,87 +0,0 @@
<?php
namespace App\Providers;
use App\Domain\DomainContext;
use App\Http\Middleware\DomainResolver;
use App\Models\UserShop;
use App\Services\DomainService;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Support\ServiceProvider;
class DomainServiceProvider extends ServiceProvider
{
/**
* Registriert die Domain-Dienste im Service-Container.
*
* @return void
*/
public function register()
{
// 1. DomainService als Singleton registrieren.
// Er wird die Konfiguration `config/domains.php` verwenden.
$this->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::warning('Domain configuration errors detected', ['errors' => $configErrors]);
}
}
return $domainService;
});
// 2. DomainContext als Singleton registrieren.
// Die Logik hier wird nur einmal pro Anfrage ausgeführt, wenn der
// Context das erste Mal benötigt wird (z.B. in der Middleware).
$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());
if (config('app.debug')) {
\Log::debug('DomainServiceProvider: domainInfo', [
'domainInfo' => $domainInfo,
'host' => $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' && $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(Kernel $kernel)
{
// Registriert die neue Middleware global für die 'web' Gruppe.
// Sie wird vor anderen Middleware ausgeführt, um den Kontext frühzeitig zu setzen.
$kernel = $this->app->make(\Illuminate\Contracts\Http\Kernel::class);
$kernel->prependMiddlewareToGroup('web', DomainResolver::class);
}
}

View file

@ -2,7 +2,8 @@
namespace App\Providers;
use App\Domain\DomainContext;
// use App\Domain\DomainContext; // HOTFIX: Temporär deaktiviert
use App\Domain\EarlyDomainParser;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
@ -32,7 +33,7 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
// $this->configureRateLimiting();
$this->configureRateLimiting();
$this->routes(function () {
// API-Routen werden global geladen
@ -44,65 +45,64 @@ class RouteServiceProvider extends ServiceProvider
// Web-Routen werden domain-bewusst geladen
Route::middleware('web')
->namespace($this->namespace)
->group(function() {
->group(function () {
$this->loadDomainAwareRoutes();
});
});
}
/**
* Lädt Routen basierend auf dem aktuellen Domain-Kontext.
* Lädt Routen basierend auf der domains.php Konfiguration.
* Vereinfachter Ansatz ohne DomainContext-Abhängigkeit
*/
protected function loadDomainAwareRoutes(): void
{
/** @var DomainContext $context */
$context = app(DomainContext::class);
$request = $this->app->make('request');
$this->loadSharedRoutes();
\Log::info('loadDomainAwareRoutes', ['context' => $context]);
match ($context->type) {
'main' => $this->loadDomainRoutes('main', 'main.php'),
'main-shop' => [
$this->loadDomainRoutes('shop', 'shop.php'),
$this->loadDomainRoutes('portal', 'portal.php'),
],
'user-shop' => [
$this->loadDomainRoutes('user-shop', 'user-shop.php'),
$this->loadDomainRoutes('portal', 'portal.php'),
],
'crm' => $this->loadDomainRoutes('crm', 'crm.php'),
'portal' => $this->loadDomainRoutes('portal', 'portal.php'),
'checkout' => $this->loadDomainRoutes('checkout', 'checkout.php'),
default => $this->loadAllDomainRoutesForCaching(),
// Lade alle Domain-spezifischen Routen
// Die Domain-Logik wird von SubdomainResolver Middleware behandelt
$domainType = EarlyDomainParser::getCurrentDomainType($request->getHost());
$routesToLoad = match ($domainType) {
'main' => ['main'],
'main-shop' => ['shop', 'portal'],
'user-shop' => ['user-shop', 'portal'],
'crm' => ['crm'],
'portal' => ['portal'],
'checkout' => ['checkout'],
'unknown' => ['main'], // Fallback für unbekannte Domains
default => ['main'],
};
foreach ($routesToLoad as $routeType) {
$this->loadDomainRoutes($routeType, $routeType . '.php');
}
if (config('app.debug')) {
\Log::channel('domain')->info('Domain-aware routes loaded', [
'domain_type' => $domainType,
'routes_loaded' => $routesToLoad,
'host' => EarlyDomainParser::parseDomain()['host'],
]);
}
}
/**
* Lädt eine spezifische Routendatei für eine Domain.
*/
protected function loadDomainRoutes(string $domainType, string $fileName): void
{
$domain = config("domains.domains.{$domainType}.host");
Route::domain($domain)
->group(base_path('routes/domains/' . $fileName));
}
$routePath = base_path('routes/domains/' . $fileName);
/**
* Lädt alle domainspezifischen Routen.
* Wird als Fallback für das Route-Caching benötigt.
*/
protected function loadAllDomainRoutesForCaching(): void
{
if (app()->routesAreCached()) {
return;
if (file_exists($routePath)) {
Route::group([], $routePath);
} else {
if (config('app.debug')) {
\Log::channel('domain')->warning('Domain route file not found', [
'domain_type' => $domainType,
'file_path' => $routePath,
]);
}
}
$this->loadDomainRoutes('main', 'main.php');
$this->loadDomainRoutes('shop', 'shop.php');
$this->loadDomainRoutes('crm', 'crm.php');
$this->loadDomainRoutes('portal', 'portal.php');
$this->loadDomainRoutes('checkout', 'checkout.php');
$this->loadDomainRoutes('user-shop', 'user-shop.php');
}
/**