mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
50e56a0396
à la racine, quand on lance le serveur, on a le framadate tel qu'il est aujourd'hui en ajoutant sur l'url, on accède à la maquette interactive dans son état actuel
63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace Framadate\Services;
|
|
|
|
class SessionService {
|
|
/**
|
|
* Get value of $key in $section, or $defaultValue
|
|
*
|
|
* @param $section
|
|
* @param $key
|
|
* @param null $defaultValue
|
|
* @return mixed
|
|
*/
|
|
public function get($section, $key, $defaultValue=null) {
|
|
assert(!empty($key));
|
|
assert(!empty($section));
|
|
|
|
$this->initSectionIfNeeded($section);
|
|
|
|
$returnValue = $defaultValue;
|
|
if (isset($_SESSION[$section][$key])) {
|
|
$returnValue = $_SESSION[$section][$key];
|
|
}
|
|
|
|
return $returnValue;
|
|
}
|
|
|
|
/**
|
|
* Set a $value for $key in $section
|
|
*
|
|
* @param $section
|
|
* @param $key
|
|
* @param $value
|
|
*/
|
|
public function set($section, $key, $value) {
|
|
assert(!empty($key));
|
|
assert(!empty($section));
|
|
|
|
$this->initSectionIfNeeded($section);
|
|
|
|
$_SESSION[$section][$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* Remove a session value
|
|
*
|
|
* @param $section
|
|
* @param $key
|
|
*/
|
|
public function remove($section, $key) {
|
|
assert(!empty($key));
|
|
assert(!empty($section));
|
|
|
|
unset($_SESSION[$section][$key]);
|
|
}
|
|
|
|
private function initSectionIfNeeded($section) {
|
|
if (!isset($_SESSION[$section])) {
|
|
$_SESSION[$section] = [];
|
|
}
|
|
}
|
|
}
|