chamilo_session.class.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * ChamiloSession class definition
  5. * @todo just the Session from the Symfony2 component
  6. */
  7. class ChamiloSession
  8. {
  9. /** @var Symfony\Component\HttpFoundation\Session\Session */
  10. public static $session;
  11. /**
  12. * @param $session
  13. */
  14. public static function setSession($session)
  15. {
  16. self::$session = $session;
  17. }
  18. /**
  19. * @param $variable
  20. * @param null $default
  21. * @return null
  22. */
  23. public static function read($variable, $default = null)
  24. {
  25. $result = self::$session->get($variable);
  26. // Check if the value exists in the $_SESSION array, to keep BC.
  27. if (!isset($result)) {
  28. return isset($_SESSION[$variable]) ? $_SESSION[$variable] : $default;
  29. } else {
  30. return $result;
  31. }
  32. }
  33. /**
  34. * @param $variable
  35. * @param $value
  36. */
  37. public static function write($variable, $value)
  38. {
  39. // Writing the session in 2 instances because
  40. $_SESSION[$variable] = $value;
  41. self::$session->set($variable, $value);
  42. }
  43. /**
  44. * @param $variable
  45. */
  46. public static function erase($variable)
  47. {
  48. self::$session->remove($variable);
  49. if (isset($GLOBALS[$variable])) {
  50. unset($GLOBALS[$variable]);
  51. }
  52. if (isset($_SESSION[$variable])) {
  53. unset($_SESSION[$variable]);
  54. }
  55. }
  56. /**
  57. *
  58. */
  59. public static function clear()
  60. {
  61. self::$session->clear();
  62. }
  63. /**
  64. * Invalidate the session.
  65. */
  66. public static function destroy()
  67. {
  68. self::$session->invalidate();
  69. }
  70. }