src/Service/UserTransient.php line 59

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * Copyright (C) Office National de Publication et de Communication - All Rights Reserved
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited by law
  7.  * This file is proprietary and confidential
  8.  */
  9. namespace App\Service;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. final class UserTransient
  12. {
  13.     // Formulaires (ids)
  14.     public const DEMANDE_INFORMATION 'demande-information';
  15.     public const DEMANDE_INFORMATION_ORPEA 'demande-information-orpea';
  16.     public const DEMANDE_INFORMATION_LNA 'demande-information-lna';
  17.     public const OFFRE_SERVICE 'offre-service';
  18.     public const OFFRE_EMPLOI_CANDIDATURE 'offre-emploi-candidature';
  19.     // Personnelles
  20.     public const CIVILITE 'civilite';
  21.     public const NOM 'nom';
  22.     public const PRENOM 'prenom';
  23.     public const TELEPHONE 'telephone';
  24.     public const EMAIL 'email';
  25.     public const AUTORISE_CONTACT 'autorise-contact';
  26.     // Navigation
  27.     public const LIEU 'lieu';
  28.     public const VILLE 'ville';
  29.     public const ROUTE_ANNUAIRE 'route-annuaire';
  30.     // Context (recherche actuelle)
  31.     public const CONTEXTE_RECHERCHE 'contexte-recherche';
  32.     private const ROUTE_ANNUAIRE_DEFAULT 'annuaire_liste';
  33.     /** @var RequestStack */
  34.     private $requestStack;
  35.     public function __construct(RequestStack $requestStack)
  36.     {
  37.         $this->requestStack $requestStack;
  38.     }
  39.     public function set(string $key$value): void
  40.     {
  41.         $this->requestStack->getSession()->set(__CLASS__.'/'.$key$value);
  42.     }
  43.     public function get(string $key)
  44.     {
  45.         $sessionKey __CLASS__.'/'.$key;
  46.         $hasInSession $this->requestStack->getSession()->has($sessionKey);
  47.         // if (self::LIEU === $key && !$hasInSession) {
  48.         //     $this->set($key, $this->geolocalisation->detect());
  49.         // } elseif (self::ROUTE_ANNUAIRE === $key && !$hasInSession) {
  50.         //     $this->set($key, self::ROUTE_ANNUAIRE_DEFAULT);
  51.         // }
  52.         // $this->set($key, self::ROUTE_ANNUAIRE_DEFAULT);
  53.         return $this->requestStack->getSession()->get($sessionKey);
  54.     }
  55. }