KeyValueStoreInterface.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Drupal\Core\KeyValueStore;
  3. /**
  4. * Defines the interface for key/value store implementations.
  5. */
  6. interface KeyValueStoreInterface {
  7. /**
  8. * Returns the name of this collection.
  9. *
  10. * @return string
  11. * The name of this collection.
  12. */
  13. public function getCollectionName();
  14. /**
  15. * Returns whether a given key exists in the store.
  16. *
  17. * @param string $key
  18. * The key to check.
  19. *
  20. * @return bool
  21. * TRUE if the key exists, FALSE otherwise.
  22. */
  23. public function has($key);
  24. /**
  25. * Returns the stored value for a given key.
  26. *
  27. * @param string $key
  28. * The key of the data to retrieve.
  29. * @param mixed $default
  30. * The default value to use if the key is not found.
  31. *
  32. * @return mixed
  33. * The stored value, or the default value if no value exists.
  34. */
  35. public function get($key, $default = NULL);
  36. /**
  37. * Returns the stored key/value pairs for a given set of keys.
  38. *
  39. * @param array $keys
  40. * A list of keys to retrieve.
  41. *
  42. * @return array
  43. * An associative array of items successfully returned, indexed by key.
  44. *
  45. * @todo What's returned for non-existing keys?
  46. */
  47. public function getMultiple(array $keys);
  48. /**
  49. * Returns all stored key/value pairs in the collection.
  50. *
  51. * @return array
  52. * An associative array containing all stored items in the collection.
  53. */
  54. public function getAll();
  55. /**
  56. * Saves a value for a given key.
  57. *
  58. * @param string $key
  59. * The key of the data to store.
  60. * @param mixed $value
  61. * The data to store.
  62. */
  63. public function set($key, $value);
  64. /**
  65. * Saves a value for a given key if it does not exist yet.
  66. *
  67. * @param string $key
  68. * The key of the data to store.
  69. * @param mixed $value
  70. * The data to store.
  71. *
  72. * @return bool
  73. * TRUE if the data was set, FALSE if it already existed.
  74. */
  75. public function setIfNotExists($key, $value);
  76. /**
  77. * Saves key/value pairs.
  78. *
  79. * @param array $data
  80. * An associative array of key/value pairs.
  81. */
  82. public function setMultiple(array $data);
  83. /**
  84. * Renames a key.
  85. *
  86. * @param string $key
  87. * The key to rename.
  88. * @param string $new_key
  89. * The new key name.
  90. */
  91. public function rename($key, $new_key);
  92. /**
  93. * Deletes an item from the key/value store.
  94. *
  95. * @param string $key
  96. * The item name to delete.
  97. */
  98. public function delete($key);
  99. /**
  100. * Deletes multiple items from the key/value store.
  101. *
  102. * @param array $keys
  103. * A list of item names to delete.
  104. */
  105. public function deleteMultiple(array $keys);
  106. /**
  107. * Deletes all items from the key/value store.
  108. */
  109. public function deleteAll();
  110. }