ComputeAndReport("Session Start"); } } public static function WriteClose() { if (self::$bSessionStarted) { $oKPI = new ExecutionKPI(); session_write_close(); self::$bSessionStarted = false; $oKPI->ComputeAndReport("Session Write Close"); } } /** * @param string|array $key key to access to the session variable. To access to $_SESSION['a']['b'] $key must be ['a', 'b'] * @param $value */ public static function Set($key, $value) { $sSessionVar = &$_SESSION; if (is_array($key)) { foreach ($key as $sKey) { $sSessionVar = &$sSessionVar[$sKey]; } } else { $sSessionVar = &$sSessionVar[$key]; } if (!self::$bSessionStarted) { self::Start(); $sSessionVar = $value; self::WriteClose(); } else { $sSessionVar = $value; } } /** * @param string|array $key key to access to the session variable. To access to $_SESSION['a']['b'] $key must be ['a', 'b'] */ public static function Unset($key) { if (self::IsSet($key)) { $aSession = $_SESSION; $sSessionVar = &$aSession; $sKey = $key; // Get the array containing the last key in order to unset the correct variable if (is_array($key)) { $sPrevKey = null; foreach ($key as $sKey) { if (!is_null($sPrevKey)) { $sSessionVar = &$sSessionVar[$sPrevKey]; } $sPrevKey = $sKey; } } if (!self::$bSessionStarted) { self::Start(); unset($sSessionVar[$sKey]); $_SESSION = $aSession; self::WriteClose(); } else { unset($sSessionVar[$sKey]); $_SESSION = $aSession; } } } /** * @param string|array $key key to access to the session variable. To access to $_SESSION['a']['b'] $key must be ['a', 'b'] * @param $default * * @return mixed */ public static function Get($key, $default = null) { $sSessionVar = &$_SESSION; if (is_array($key)) { foreach ($key as $SKey) { $sSessionVar = &$sSessionVar[$SKey]; } } else { $sSessionVar = &$sSessionVar[$key]; } if (isset($sSessionVar)) { return $sSessionVar; } return $default; } /** * @param string|array $key key to access to the session variable. To access to $_SESSION['a']['b'] $key must be ['a', 'b'] * * @return bool */ public static function IsSet($key): bool { $sSessionVar = &$_SESSION; if (is_array($key)) { foreach ($key as $SKey) { $sSessionVar = &$sSessionVar[$SKey]; } } else { $sSessionVar = &$sSessionVar[$key]; } return isset($sSessionVar); } public static function ListVariables(): array { return array_keys($_SESSION); } }