memory.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\Session;
  9. /**
  10. * Class Internal
  11. *
  12. * store session data in an in-memory array, not persistance
  13. *
  14. * @package OC\Session
  15. */
  16. class Memory extends Session {
  17. protected $data;
  18. public function __construct($name) {
  19. //no need to use $name since all data is already scoped to this instance
  20. $this->data = array();
  21. }
  22. /**
  23. * @param string $key
  24. * @param mixed $value
  25. */
  26. public function set($key, $value) {
  27. $this->data[$key] = $value;
  28. }
  29. /**
  30. * @param string $key
  31. * @return mixed
  32. */
  33. public function get($key) {
  34. if (!$this->exists($key)) {
  35. return null;
  36. }
  37. return $this->data[$key];
  38. }
  39. /**
  40. * @param string $key
  41. * @return bool
  42. */
  43. public function exists($key) {
  44. return isset($this->data[$key]);
  45. }
  46. /**
  47. * @param string $key
  48. */
  49. public function remove($key) {
  50. unset($this->data[$key]);
  51. }
  52. public function clear() {
  53. $this->data = array();
  54. }
  55. }