Files
kupshop/bundles/External/CykloSpecialityBundle/Controller/CykloSpecialityController.php
2025-08-02 16:30:27 +02:00

39 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace External\CykloSpecialityBundle\Controller;
use KupShop\I18nBundle\Util\Locale\LanguageAwareUrlGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;
class CykloSpecialityController extends AbstractController
{
#[Route('/_cyklospeciality/redirect/{country}')]
public function redirectByCountry(Request $request, LanguageAwareUrlGenerator $urlGenerator, string $country): RedirectResponse
{
$config = [
'CZ' => ['cs', 'https://cyklospeciality.cz'],
'SK' => ['sk', 'https://cyklospeciality.sk'],
];
[$language, $domain] = $config[$country];
$referer = str_replace($request->getSchemeAndHttpHost(), '', $request->headers->get('referer', '/'));
try {
$url = $urlGenerator->generateInLanguage($language, $referer);
} catch (\Exception $e) {
throw new NotFoundHttpException('Failure when generating URL');
}
return new RedirectResponse(
$domain.$url
);
}
}