Skip to content

Commit

Permalink
Add main request assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
senghe committed Nov 14, 2023
1 parent 24ed2ad commit ac2fae7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/CommandHandler/Wishlist/CreateWishlistHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Webmozart\Assert\Assert;

final class CreateWishlistHandler implements MessageHandlerInterface
{
Expand Down Expand Up @@ -79,6 +80,8 @@ public function __invoke(CreateWishlist $createWishlist): WishlistInterface
{
$wishlist->setToken($createWishlist->getTokenValue());
$mainRequest = $this->requestStack->getMainRequest();

Assert::notNull($mainRequest, 'The handler is destined to HTTP context only');
$mainRequest->attributes->set($this->wishlistCookieToken, $createWishlist->getTokenValue());
}

Expand Down

0 comments on commit ac2fae7

Please sign in to comment.