src/Services/SessionService.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Services;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\Security\Core\Security;
  6. class SessionService
  7. {
  8.     private EntityManagerInterface $entityManager;
  9.     private RequestStack $request;
  10.     private Security $security;
  11.     public function __construct(EntityManagerInterface $entityManagerSecurity $securityRequestStack $request)
  12.     {
  13.         $this->security $security;
  14.         $this->entityManager $entityManager;
  15.         $this->request $request;
  16.     }
  17.     public function _getBaseParameters()
  18.     {
  19.         $request $this->request->getCurrentRequest();
  20.         $session $request->getSession();
  21.         $user $this->security->getUser();
  22.         $username = ($user) ? $user->getUsername() : false;
  23.         $data = array(
  24.             "language" => $request->getLocale(),
  25.             "username" => $username,
  26.         );
  27.         if ($session->get('code')) {
  28.             $data["code"] = $session->get('code');
  29.             $data["firstname"] = $session->get('firstname');
  30.             $data["lastname"] = $session->get('lastname');
  31.             $data["elligible"] = $session->get('elligible');
  32.         } else {
  33.             $data["elligible"] = false;
  34.             $data["code"] = false;
  35.             $data["firstname"] = false;
  36.             $data["lastname"] = false;
  37.         }
  38.         return $data;
  39.     }
  40.     public function expireSession()
  41.     {
  42.         $request $this->request->getCurrentRequest();
  43.         $session $request->getSession();
  44.         $session->invalidate();
  45.     }
  46. }