Optimierung 4.1: Web-Portal-/Domain-Kontext extrahiert
- WebPortalContext::fromRequest() buendelt die zuvor ~6x je Route-Closure wiederholte Host->Portal-Ableitung (portal, language, portalValues, domainConfig). - DomainAssetContext::applyWebDomainConfig() ist die Single Source of Truth fuer die Domain-/Theme-Anwendung (config + View::share + Vite); die fruehere $applyWebDomainConfig-Closure in routes/web.php ist nur noch ein duenner Delegations-Wrapper, damit Bare-Root- und Edition-Home-Route unveraendert per Closure aufrufen koennen. - Die 6 Portal-Seiten-Closures (Kategorie, Detail, Veroeffentlichen, Suche, Newsrooms, Newsroom-Detail) sowie Preise nutzen jetzt den zentralen Kontext. Abgesichert durch die 92 Web/-Tests (jede Seite laeuft ueber den neuen Kontext). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f20a95f9a4
commit
714a5cd5b1
4 changed files with 106 additions and 98 deletions
|
|
@ -3,10 +3,42 @@
|
|||
namespace App\Support;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
|
||||
class DomainAssetContext
|
||||
{
|
||||
/**
|
||||
* Wendet die Domain-/Theme-Konfiguration einer öffentlichen Web-Ausgabe an
|
||||
* (config + View::share + Vite) und liefert die aufgelöste Domain-Config.
|
||||
* Single Source of Truth für die zuvor je Route-Closure wiederholte Logik.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function applyWebDomainConfig(string $domainKey): array
|
||||
{
|
||||
/** @var array<string, mixed> $domainConfig */
|
||||
$domainConfig = config("domains.domains.{$domainKey}", []);
|
||||
|
||||
config([
|
||||
'app.theme' => $domainConfig['theme'] ?? $domainKey,
|
||||
'app.view_prefix' => $domainConfig['view_prefix'] ?? 'web',
|
||||
'app.domain_name' => $domainConfig['domain_name'] ?? request()->getHost(),
|
||||
'app.url' => $domainConfig['url'] ?? config('app.url'),
|
||||
]);
|
||||
|
||||
View::share('theme', $domainConfig['theme'] ?? $domainKey);
|
||||
View::share('viewPrefix', $domainConfig['view_prefix'] ?? 'web');
|
||||
View::share('domainName', $domainConfig['domain_name'] ?? request()->getHost());
|
||||
View::share('domainConfig', $domainConfig);
|
||||
View::share('domainUrl', $domainConfig['url'] ?? config('app.url'));
|
||||
View::share('assetUrl', self::staticAssetOrigin($domainConfig));
|
||||
|
||||
self::configureVite($domainConfig);
|
||||
|
||||
return $domainConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $defaults
|
||||
* @param array<string, array<string, mixed>> $configuredDomains
|
||||
|
|
|
|||
42
app/Support/WebPortalContext.php
Normal file
42
app/Support/WebPortalContext.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Enums\Portal;
|
||||
|
||||
/**
|
||||
* Öffentlicher Portal-Kontext (Presseecho/Businessportal24) einer Web-Landingpage,
|
||||
* abgeleitet aus dem Host. Bündelt die zuvor in jeder Route-Closure wiederholte
|
||||
* Host→Portal-Ableitung samt Anwendung der Domain-/Theme-Konfiguration.
|
||||
*/
|
||||
class WebPortalContext
|
||||
{
|
||||
/**
|
||||
* @param list<string> $portalValues Eigenes Portal plus `both`.
|
||||
* @param array<string, mixed> $domainConfig
|
||||
*/
|
||||
private function __construct(
|
||||
public readonly string $domainKey,
|
||||
public readonly Portal $portal,
|
||||
public readonly string $language,
|
||||
public readonly array $portalValues,
|
||||
public readonly array $domainConfig,
|
||||
) {}
|
||||
|
||||
public static function fromRequest(): self
|
||||
{
|
||||
$host = request()->getHost();
|
||||
|
||||
[$domainKey, $portal] = str_contains($host, 'presseecho')
|
||||
? ['presseecho', Portal::Presseecho]
|
||||
: ['businessportal24', Portal::Businessportal24];
|
||||
|
||||
return new self(
|
||||
domainKey: $domainKey,
|
||||
portal: $portal,
|
||||
language: app()->getLocale(),
|
||||
portalValues: [$portal->value, Portal::Both->value],
|
||||
domainConfig: DomainAssetContext::applyWebDomainConfig($domainKey),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue