src/Module/Store/Integration/Subscriber/LocaleSubscriber.php line 46

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Module\Store\Integration\Subscriber;
  4. use App\Locale\LocaleProviderInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\Cookie;
  7. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  8. /**
  9. * @package App\Module\Store\Integration\Subscriber
  10. */
  11. class LocaleSubscriber implements EventSubscriberInterface
  12. {
  13. private LocaleProviderInterface $localeProvider;
  14. /**
  15. * @param LocaleProviderInterface $localeProvider
  16. */
  17. public function __construct(LocaleProviderInterface $localeProvider)
  18. {
  19. $this->localeProvider = $localeProvider;
  20. }
  21. /**
  22. * @return string[][]
  23. */
  24. public static function getSubscribedEvents(): array
  25. {
  26. return [
  27. 'kernel.response' => [
  28. 'attachCurrentLocale'
  29. ]
  30. ];
  31. }
  32. /**
  33. *
  34. *
  35. * @param ResponseEvent $responseEvent
  36. *
  37. * @return void
  38. */
  39. public function attachCurrentLocale(ResponseEvent $responseEvent): void
  40. {
  41. $responseEvent
  42. ->getResponse()
  43. ->headers
  44. ->setCookie(
  45. new Cookie(
  46. 'currentlocale_denios',
  47. str_replace(
  48. '_',
  49. '-',
  50. strtolower($this->localeProvider->getLocaleInfo()->getCurrentLocale())
  51. ),
  52. 0,
  53. '/',
  54. null,
  55. null,
  56. false,
  57. false,
  58. 'None'
  59. )
  60. );
  61. }
  62. }