<?php
declare(strict_types=1);
/*
* Copyright (C) Office National de Publication et de Communication - All Rights Reserved
*
* Unauthorized copying of this file, via any medium is strictly prohibited by law
* This file is proprietary and confidential
*/
namespace App\Service;
use Symfony\Component\HttpFoundation\RequestStack;
final class UserTransient
{
// Formulaires (ids)
public const DEMANDE_INFORMATION = 'demande-information';
public const DEMANDE_INFORMATION_ORPEA = 'demande-information-orpea';
public const DEMANDE_INFORMATION_LNA = 'demande-information-lna';
public const OFFRE_SERVICE = 'offre-service';
public const OFFRE_EMPLOI_CANDIDATURE = 'offre-emploi-candidature';
// Personnelles
public const CIVILITE = 'civilite';
public const NOM = 'nom';
public const PRENOM = 'prenom';
public const TELEPHONE = 'telephone';
public const EMAIL = 'email';
public const AUTORISE_CONTACT = 'autorise-contact';
// Navigation
public const LIEU = 'lieu';
public const VILLE = 'ville';
public const ROUTE_ANNUAIRE = 'route-annuaire';
// Context (recherche actuelle)
public const CONTEXTE_RECHERCHE = 'contexte-recherche';
private const ROUTE_ANNUAIRE_DEFAULT = 'annuaire_liste';
/** @var RequestStack */
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function set(string $key, $value): void
{
$this->requestStack->getSession()->set(__CLASS__.'/'.$key, $value);
}
public function get(string $key)
{
$sessionKey = __CLASS__.'/'.$key;
$hasInSession = $this->requestStack->getSession()->has($sessionKey);
// if (self::LIEU === $key && !$hasInSession) {
// $this->set($key, $this->geolocalisation->detect());
// } elseif (self::ROUTE_ANNUAIRE === $key && !$hasInSession) {
// $this->set($key, self::ROUTE_ANNUAIRE_DEFAULT);
// }
// $this->set($key, self::ROUTE_ANNUAIRE_DEFAULT);
return $this->requestStack->getSession()->get($sessionKey);
}
}