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