No Description

StoreMemory.php 711B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class LtStoreMemory implements LtStore
  3. {
  4. protected $stack;
  5. public function add($key, $value)
  6. {
  7. if (isset($this->stack[$key]))
  8. {
  9. return false;
  10. }
  11. else
  12. {
  13. $this->stack[$key] = $value;
  14. return true;
  15. }
  16. }
  17. public function del($key)
  18. {
  19. if (isset($this->stack[$key]))
  20. {
  21. unset($this->stack[$key]);
  22. return true;
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29. public function get($key)
  30. {
  31. return isset($this->stack[$key]) ? $this->stack[$key] : false;
  32. }
  33. /**
  34. * key不存在返回false
  35. *
  36. * @return bool
  37. */
  38. public function update($key, $value)
  39. {
  40. if (!isset($this->stack[$key]))
  41. {
  42. return false;
  43. }
  44. else
  45. {
  46. $this->stack[$key] = $value;
  47. return true;
  48. }
  49. }
  50. }