commit 08-2025

This commit is contained in:
Kevin Adametz 2025-08-12 18:01:59 +02:00
parent 9ae662f63e
commit 480fdc65ed
404 changed files with 65310 additions and 2600431 deletions

View file

@ -4,6 +4,7 @@ namespace App\Providers;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;
class AppServiceProvider extends ServiceProvider
{
@ -15,6 +16,29 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
Schema::defaultStringLength(191);
if ($this->app->environment('production')) {
URL::forceScheme('https');
}
// Domain-bewusster View Composer für user_shop
\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);
}
} catch (\Exception $e) {
// Fallback bei Fehlern
$view->with('user_shop', \App\Services\Util::getUserShop());
}
});
}
/**

View file

@ -25,7 +25,12 @@ class AuthServiceProvider extends ServiceProvider
public function boot()
{
$this->registerPolicies();
Passport::routes();
// Die neuere Passport-Konfiguration verwendet separate Methoden
// anstelle von Passport::routes()
Passport::tokensExpireIn(now()->addDays(15));
Passport::refreshTokensExpireIn(now()->addDays(30));
Passport::personalAccessTokensExpireIn(now()->addMonths(6));
//
}

View file

@ -0,0 +1,85 @@
<?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());
\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,19 +2,28 @@
namespace App\Providers;
use Illuminate\Support\Facades\Route;
use App\Domain\DomainContext;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
* The path to the "home" route for your application.
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
public const HOME = '/';
/**
* The controller namespace for the application.
*
* @var string|null
*/
protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
@ -23,57 +32,97 @@ class RouteServiceProvider extends ServiceProvider
*/
public function boot()
{
parent::boot();
// $this->configureRateLimiting();
$this->routes(function () {
// API-Routen werden global geladen
Route::domain('api.' . config('app.domain') . config('app.tld_care'))
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
// Web-Routen werden domain-bewusst geladen
Route::middleware('web')
->namespace($this->namespace)
->group(function() {
$this->loadDomainAwareRoutes();
});
});
}
/**
* Define the routes for the application.
*
* @return void
* Lädt Routen basierend auf dem aktuellen Domain-Kontext.
*/
public function map()
protected function loadDomainAwareRoutes(): void
{
$this->mapApiRoutes();
/** @var DomainContext $context */
$context = app(DomainContext::class);
$this->loadSharedRoutes();
$this->mapWebRoutes();
//
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(),
};
}
/**
* 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));
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
* Lädt alle domainspezifischen Routen.
* Wird als Fallback für das Route-Caching benötigt.
*/
protected function mapWebRoutes()
protected function loadAllDomainRoutesForCaching(): void
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
if (app()->routesAreCached()) {
return;
}
$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');
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
* Lädt Routen, die auf allen Domains verfügbar sein sollen.
*/
protected function loadSharedRoutes(): void
{
// Lädt Routen, die auf allen Domains verfügbar sein sollen.
Route::group([], base_path('routes/shared/common.php'));
}
/**
* Konfiguriert die Rate-Limiter für die Anwendung.
*
* @return void
*/
protected function mapApiRoutes()
protected function configureRateLimiting()
{
Route::domain('api.'.config('app.domain').config('app.tld_care'))
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
//.
/* Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
*/
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}