You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when i type bin/console debug:event-dispatcher -vvv
the command is blocked by:
[Webmozart\Assert\InvalidArgumentException]
The class has to be used in HTTP context only
Webmozart\Assert\Assert::notNull() at vendor/bitbag/wishlist-plugin/src/EventSubscriber/CreateNewWishlistSubscriber.php:48
I modified the code by not injecting the Request into constructor and using the request object from the RequestEvent. Also removed the Assert.
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
$currentPath = $request->getPathInfo();
if (!str_starts_with($currentPath, self::ALLOWED_ENDPOINTS_PREFIX)) {
return;
}
/** @var WishlistInterface[] $wishlists */
$wishlists = $this->wishlistsResolver->resolve();
$wishlistCookieToken = $request->cookies->get($this->wishlistCookieToken);
if (!empty($wishlists)) {
if (null === $wishlistCookieToken) {
$request->attributes->set($this->wishlistCookieToken, reset($wishlists)->getToken());
}
return;
}
if (null === $wishlistCookieToken) {
$wishlistCookieToken = $this->wishlistCookieTokenResolver->resolve();
}
$request->attributes->set($this->wishlistCookieToken, $wishlistCookieToken);
}
public function onKernelResponse(ResponseEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
if (!str_starts_with($request->getPathInfo(), self::ALLOWED_ENDPOINTS_PREFIX)) {
return;
}
if ($request->cookies->has($this->wishlistCookieToken)) {
return;
}
$response = $event->getResponse();
$wishlistCookieToken = $request->attributes->get($this->wishlistCookieToken);
if (!$wishlistCookieToken) {
return;
}
$cookie = new Cookie($this->wishlistCookieToken, $wishlistCookieToken, strtotime('+1 year'));
$response->headers->setCookie($cookie);
$request->attributes->remove($this->wishlistCookieToken);
}
The text was updated successfully, but these errors were encountered:
when i type
bin/console debug:event-dispatcher -vvv
the command is blocked by:
I modified the code by not injecting the
Request
into constructor and using the request object from theRequestEvent
. Also removed the Assert.The text was updated successfully, but these errors were encountered: