<?php
declare(strict_types=1);
namespace WebBundle\Handler\Locale\Rule;
use Symfony\Component\HttpFoundation\Response;
/**
* Проверяет: если это job site - то правим куки нет локали в url - ru, есть локаль в url - en
*/
class CheckJobSiteRuleHandler extends AbstractRuleHandler
{
public function execute(): ?Response
{
// делаю чтоб job сайт откликался только на локаль в урле
$host = $this->machineLocaleHandler->getRequest()->getHost();
if (str_starts_with($host, 'jobs')) {
$langToUrl = $this->machineLocaleHandler->getLangToUrl();
$countryToUrl = $this->machineLocaleHandler->getCountryToUrl();
if ($langToUrl !== 'en') {
$langToUrl = 'ru';
}
if ($countryToUrl !== 'us') {
$countryToUrl = 'us';
}
$this->machineLocaleHandler->setLangCookie($langToUrl);
$this->machineLocaleHandler->setCountryCookie($countryToUrl);
$this->machineLocaleHandler->setLangToUrl($langToUrl);
$this->machineLocaleHandler->setCountryToUrl($countryToUrl);
$this->machineLocaleHandler->setUserApprovedCookie(false);
$this->machineLocaleHandler->getRequest()->setLocale($this->machineLocaleHandler->getLocaleByMainCookie());
$this->machineLocaleHandler->updateCookieSet();
return null;
}
$this->nextStep(CheckValidAndNotEmptyLocaleInUrlRuleHandler::getRule($this->machineLocaleHandler));
return parent::execute();
}
}