feat: domain-based theme-detection

This commit is contained in:
Björn Fromme
2026-01-27 11:18:37 +01:00
parent 2355442ac0
commit d5944bf717
9 changed files with 189 additions and 38 deletions
@@ -103,9 +103,6 @@ class IndexController extends AbstractController
// Store optional return URL in session (defaults to main EP site)
$this->bookingService->storeReturnUrl($request, $params->returnUrl);
// Store theme for consistent styling throughout the booking flow
$this->bookingService->storeTheme($request, $params->theme);
// Create fresh booking session with the provided parameters
$bookingDto = $this->bookingService->startFreshBooking($request, $dateId, $hotelId, $agencyId);
+52
View File
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace App\EventListener;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
#[AsEventListener(event: KernelEvents::REQUEST, priority: 200)]
class DomainThemeListener
{
public const THEME_ATTRIBUTE = '_theme';
private const DEFAULT_THEME = 'base';
/**
* @param array<string, string> $domainThemeMap
*/
public function __construct(
private readonly array $domainThemeMap,
) {
}
public function __invoke(RequestEvent $event): void
{
if (false === $event->isMainRequest()) {
return;
}
$request = $event->getRequest();
$host = $request->getHost();
$theme = $this->resolveTheme($host);
$request->attributes->set(self::THEME_ATTRIBUTE, $theme);
}
private function resolveTheme(string $host): string
{
$host = strtolower($host);
foreach ($this->domainThemeMap as $pattern => $theme) {
$pattern = strtolower($pattern);
if ($host === $pattern || str_ends_with($host, '.' . $pattern)) {
return $theme;
}
}
return self::DEFAULT_THEME;
}
}
-1
View File
@@ -21,7 +21,6 @@ readonly class BookingQueryParams
public int $hotelId,
public ?string $agency = null,
public string $theme = 'base',
#[SerializedName('r')]
public ?string $returnUrl = null,
-29
View File
@@ -22,8 +22,6 @@ class BookingService
public const BOOKING_EDIT_KEY = 'booking_edit';
public const RETURN_URL_KEY = 'booking_return_url';
public const DEFAULT_RETURN_URL = 'https://www.ep-reisen.de';
public const THEME_KEY = 'booking_theme';
public const DEFAULT_THEME = 'base';
public function __construct(
private readonly TravelDataService $travelDataService,
@@ -195,33 +193,6 @@ class BookingService
return $request->getSession()->get(self::RETURN_URL_KEY, self::DEFAULT_RETURN_URL);
}
/**
* Stores the theme identifier in the session.
*
* Sanitizes the theme value to allow only alphanumeric characters and hyphens.
* Falls back to the default theme if empty or invalid.
*/
public function storeTheme(Request $request, string $theme): void
{
$sanitized = preg_replace('/[^a-zA-Z0-9-]/', '', $theme);
if ('' === $sanitized) {
$sanitized = self::DEFAULT_THEME;
}
$request->getSession()->set(self::THEME_KEY, $sanitized);
}
/**
* Retrieves the theme identifier from the session.
*
* Returns the default theme if not set in session.
*/
public function getTheme(Request $request): string
{
return $request->getSession()->get(self::THEME_KEY, self::DEFAULT_THEME);
}
/**
* Creates a fresh booking session with the provided travel parameters.
*
+6 -4
View File
@@ -5,10 +5,10 @@ declare(strict_types=1);
namespace App\Twig;
use App\BusProNet\DataProvider\CountryDataProvider;
use App\EventListener\DomainThemeListener;
use App\Form\Model\BookingDto;
use App\Form\Service\CreateFieldStateProvider;
use App\Form\Service\EditFieldStateProvider;
use App\Service\BookingService;
use App\Service\ParticipantEligibilityService;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -228,18 +228,20 @@ class AppRuntime implements RuntimeExtensionInterface
}
/**
* Returns the current booking theme from session.
* Returns the current booking theme from request attribute.
*
* The theme is resolved by DomainThemeListener based on the request host.
* Defaults to 'base' if no theme is set.
*/
public function getBookingTheme(): string
{
$request = $this->requestStack->getCurrentRequest();
if (null === $request) {
return BookingService::DEFAULT_THEME;
return 'base';
}
return $request->getSession()->get(BookingService::THEME_KEY, BookingService::DEFAULT_THEME);
return $request->attributes->get(DomainThemeListener::THEME_ATTRIBUTE, 'base');
}
/**