src/WebBundle/Handler/Locale/Rule/CheckJobSiteRuleHandler.php line 42

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WebBundle\Handler\Locale\Rule;
  4. use Symfony\Component\HttpFoundation\Response;
  5. /**
  6.  * Проверяет: если это job site - то правим куки нет локали в url - ru, есть локаль в url - en
  7.  */
  8. class CheckJobSiteRuleHandler extends AbstractRuleHandler
  9. {
  10.     public function execute(): ?Response
  11.     {
  12.         // делаю чтоб job сайт откликался только на локаль в урле
  13.         $host $this->machineLocaleHandler->getRequest()->getHost();
  14.         if (str_starts_with($host'jobs')) {
  15.             $langToUrl $this->machineLocaleHandler->getLangToUrl();
  16.             $countryToUrl $this->machineLocaleHandler->getCountryToUrl();
  17.             if ($langToUrl !== 'en') {
  18.                 $langToUrl 'ru';
  19.             }
  20.             if ($countryToUrl !== 'us') {
  21.                 $countryToUrl 'us';
  22.             }
  23.             $this->machineLocaleHandler->setLangCookie($langToUrl);
  24.             $this->machineLocaleHandler->setCountryCookie($countryToUrl);
  25.             $this->machineLocaleHandler->setLangToUrl($langToUrl);
  26.             $this->machineLocaleHandler->setCountryToUrl($countryToUrl);
  27.             $this->machineLocaleHandler->setUserApprovedCookie(false);
  28.             $this->machineLocaleHandler->getRequest()->setLocale($this->machineLocaleHandler->getLocaleByMainCookie());
  29.             $this->machineLocaleHandler->updateCookieSet();
  30.             return null;
  31.         }
  32.         $this->nextStep(CheckValidAndNotEmptyLocaleInUrlRuleHandler::getRule($this->machineLocaleHandler));
  33.         return parent::execute();
  34.     }
  35. }