StorageInterface.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace Drupal\Core\Config;
  3. /**
  4. * Defines an interface for configuration storage.
  5. *
  6. * Classes implementing this interface allow reading and writing configuration
  7. * data from and to the storage.
  8. */
  9. interface StorageInterface {
  10. /**
  11. * The default collection name.
  12. */
  13. const DEFAULT_COLLECTION = '';
  14. /**
  15. * Returns whether a configuration object exists.
  16. *
  17. * @param string $name
  18. * The name of a configuration object to test.
  19. *
  20. * @return bool
  21. * TRUE if the configuration object exists, FALSE otherwise.
  22. */
  23. public function exists($name);
  24. /**
  25. * Reads configuration data from the storage.
  26. *
  27. * @param string $name
  28. * The name of a configuration object to load.
  29. *
  30. * @return array|bool
  31. * The configuration data stored for the configuration object name. If no
  32. * configuration data exists for the given name, FALSE is returned.
  33. */
  34. public function read($name);
  35. /**
  36. * Reads configuration data from the storage.
  37. *
  38. * @param array $names
  39. * List of names of the configuration objects to load.
  40. *
  41. * @return array
  42. * A list of the configuration data stored for the configuration object name
  43. * that could be loaded for the passed list of names.
  44. */
  45. public function readMultiple(array $names);
  46. /**
  47. * Writes configuration data to the storage.
  48. *
  49. * @param string $name
  50. * The name of a configuration object to save.
  51. * @param array $data
  52. * The configuration data to write.
  53. *
  54. * @return bool
  55. * TRUE on success, FALSE in case of an error.
  56. *
  57. * @throws \Drupal\Core\Config\StorageException
  58. * If the back-end storage does not exist and cannot be created.
  59. */
  60. public function write($name, array $data);
  61. /**
  62. * Deletes a configuration object from the storage.
  63. *
  64. * @param string $name
  65. * The name of a configuration object to delete.
  66. *
  67. * @return bool
  68. * TRUE on success, FALSE otherwise.
  69. */
  70. public function delete($name);
  71. /**
  72. * Renames a configuration object in the storage.
  73. *
  74. * @param string $name
  75. * The name of a configuration object to rename.
  76. * @param string $new_name
  77. * The new name of a configuration object.
  78. *
  79. * @return bool
  80. * TRUE on success, FALSE otherwise.
  81. */
  82. public function rename($name, $new_name);
  83. /**
  84. * Encodes configuration data into the storage-specific format.
  85. *
  86. * This is a publicly accessible static method to allow for alternative
  87. * usages in data conversion scripts and also tests.
  88. *
  89. * @param array $data
  90. * The configuration data to encode.
  91. *
  92. * @return string
  93. * The encoded configuration data.
  94. */
  95. public function encode($data);
  96. /**
  97. * Decodes configuration data from the storage-specific format.
  98. *
  99. * This is a publicly accessible static method to allow for alternative
  100. * usages in data conversion scripts and also tests.
  101. *
  102. * @param string $raw
  103. * The raw configuration data string to decode.
  104. *
  105. * @return array
  106. * The decoded configuration data as an associative array.
  107. */
  108. public function decode($raw);
  109. /**
  110. * Gets configuration object names starting with a given prefix.
  111. *
  112. * Given the following configuration objects:
  113. * - node.type.article
  114. * - node.type.page
  115. *
  116. * Passing the prefix 'node.type.' will return an array containing the above
  117. * names.
  118. *
  119. * @param string $prefix
  120. * (optional) The prefix to search for. If omitted, all configuration object
  121. * names that exist are returned.
  122. *
  123. * @return array
  124. * An array containing matching configuration object names.
  125. */
  126. public function listAll($prefix = '');
  127. /**
  128. * Deletes configuration objects whose names start with a given prefix.
  129. *
  130. * Given the following configuration object names:
  131. * - node.type.article
  132. * - node.type.page
  133. *
  134. * Passing the prefix 'node.type.' will delete the above configuration
  135. * objects.
  136. *
  137. * @param string $prefix
  138. * (optional) The prefix to search for. If omitted, all configuration
  139. * objects that exist will be deleted.
  140. *
  141. * @return bool
  142. * TRUE on success, FALSE otherwise.
  143. */
  144. public function deleteAll($prefix = '');
  145. /**
  146. * Creates a collection on the storage.
  147. *
  148. * A configuration storage can contain multiple sets of configuration objects
  149. * in partitioned collections. The collection name identifies the current
  150. * collection used.
  151. *
  152. * Implementations of this method must provide a new instance to avoid side
  153. * effects caused by the fact that Config objects have their storage injected.
  154. *
  155. * @param string $collection
  156. * The collection name. Valid collection names conform to the following
  157. * regex [a-zA-Z_.]. A storage does not need to have a collection set.
  158. * However, if a collection is set, then storage should use it to store
  159. * configuration in a way that allows retrieval of configuration for a
  160. * particular collection.
  161. *
  162. * @return \Drupal\Core\Config\StorageInterface
  163. * A new instance of the storage backend with the collection set.
  164. */
  165. public function createCollection($collection);
  166. /**
  167. * Gets the existing collections.
  168. *
  169. * A configuration storage can contain multiple sets of configuration objects
  170. * in partitioned collections. The collection key name identifies the current
  171. * collection used.
  172. *
  173. * @return array
  174. * An array of existing collection names.
  175. */
  176. public function getAllCollectionNames();
  177. /**
  178. * Gets the name of the current collection the storage is using.
  179. *
  180. * @return string
  181. * The current collection name.
  182. */
  183. public function getCollectionName();
  184. }