<?php
namespace App\Services;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
class SessionService
{
private EntityManagerInterface $entityManager;
private RequestStack $request;
private Security $security;
public function __construct(EntityManagerInterface $entityManager, Security $security, RequestStack $request)
{
$this->security = $security;
$this->entityManager = $entityManager;
$this->request = $request;
}
public function _getBaseParameters()
{
$request = $this->request->getCurrentRequest();
$session = $request->getSession();
$user = $this->security->getUser();
$username = ($user) ? $user->getUsername() : false;
$data = array(
"language" => $request->getLocale(),
"username" => $username,
);
if ($session->get('code')) {
$data["code"] = $session->get('code');
$data["firstname"] = $session->get('firstname');
$data["lastname"] = $session->get('lastname');
$data["elligible"] = $session->get('elligible');
} else {
$data["elligible"] = false;
$data["code"] = false;
$data["firstname"] = false;
$data["lastname"] = false;
}
return $data;
}
public function expireSession()
{
$request = $this->request->getCurrentRequest();
$session = $request->getSession();
$session->invalidate();
}
}