1111
1212namespace BitBag \SyliusUserComPlugin \Manager ;
1313
14+ use BitBag \SyliusUserComPlugin \Cookie \CookieQueueInterface ;
1415use Sylius \Component \Core \Model \AdminUserInterface ;
16+ use Symfony \Component \HttpFoundation \Cookie ;
1517use Symfony \Component \HttpFoundation \RequestStack ;
1618use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
1719
@@ -20,6 +22,8 @@ final class CookieManager implements CookieManagerInterface
2022 public function __construct (
2123 private readonly RequestStack $ requestStack ,
2224 private readonly TokenStorageInterface $ tokenStorage ,
25+ private readonly CookieQueueInterface $ queue ,
26+ private readonly ?string $ cookieDomain = null ,
2327 ) {
2428 }
2529
@@ -41,11 +45,18 @@ public function getUserComCookie(): ?string
4145
4246 public function setUserComCookie (string $ value ): void
4347 {
44- $ request = $ this ->requestStack ->getCurrentRequest ();
45- if (null === $ request ) {
46- return ;
48+ $ cookie = Cookie::create (self ::CHAT_COOKIE_NAME )
49+ ->withValue ($ value )
50+ ->withPath ('' )
51+ ->withSecure (true )
52+ ->withHttpOnly (true )
53+ ->withSameSite ('lax ' );
54+
55+ if (null !== $ this ->cookieDomain && '' !== $ this ->cookieDomain ) {
56+ $ cookie = $ cookie ->withDomain ($ this ->cookieDomain );
4757 }
48- $ request ->cookies ->set (self ::CHAT_COOKIE_NAME , $ value );
58+
59+ $ this ->queue ->queue ($ cookie );
4960 }
5061
5162 private function isShopUser (): bool
0 commit comments