<?php
/**
* Créé par Aropixel @2022.
* Par: Joël Gomez Caballe
* Date: 19/06/2022 à 12:05
*/
namespace TickLive\ShopBundle\Infrastructure\Feature\Front\Checkout\Guest;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use TickLive\ShopBundle\Domain\Component\Ecommerce\Guest\GuestLoggerInterface;
use TickLive\ShopBundle\Entity\Customer;
class GuestLogger implements GuestLoggerInterface
{
private SessionInterface $session;
/** @var string */
const GUEST_LOG_KEY = '_ticklive.guest';
/**
* @param SessionInterface $session
*/
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
public function logIn(Customer $customer): void
{
$this->session->set(self::GUEST_LOG_KEY, $customer->getId());
$this->session->save();
}
public function logOut(): void
{
$this->session->remove(self::GUEST_LOG_KEY);
$this->session->save();
}
public function isLogged(): bool
{
return $this->session->has(self::GUEST_LOG_KEY);
}
}