StorageInterface.php 4.11 KB
Newer Older
gdd's avatar
gdd committed
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Definition of Drupal\Core\Config\StorageInterface.
 */

gdd's avatar
gdd committed
8 9 10
namespace Drupal\Core\Config;

/**
11
 * Defines an interface for configuration storage.
gdd's avatar
gdd committed
12
 *
13 14
 * Classes implementing this interface allow reading and writing configuration
 * data from and to the storage.
gdd's avatar
gdd committed
15
 */
16
interface StorageInterface {
gdd's avatar
gdd committed
17 18

  /**
19
   * Returns whether a configuration object exists.
gdd's avatar
gdd committed
20
   *
21 22 23 24 25
   * @param string $name
   *   The name of a configuration object to test.
   *
   * @return bool
   *   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 33
   * @param string $name
   *   The name of a configuration object to load.
gdd's avatar
gdd committed
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.
gdd's avatar
gdd committed
38
   */
39
  public function read($name);
gdd's avatar
gdd committed
40

41 42 43
  /**
   * Reads configuration data from the storage.
   *
44
   * @param array $names
45 46 47 48 49 50 51 52
   *   List of names of the configuration objects to load.
   *
   * @return array
   *   A list of the configuration data stored for the configuration object name
   *   that could be loaded for the passed list of names.
   */
  public function readMultiple(array $names);

gdd's avatar
gdd committed
53
  /**
54
   * Writes configuration data to the storage.
gdd's avatar
gdd committed
55
   *
56 57 58 59
   * @param string $name
   *   The name of a configuration object to save.
   * @param array $data
   *   The configuration data to write.
60
   *
61 62
   * @return bool
   *   TRUE on success, FALSE in case of an error.
63 64 65
   *
   * @throws \Drupal\Core\Config\StorageException
   *   If the back-end storage does not exist and cannot be created.
gdd's avatar
gdd committed
66
   */
67
  public function write($name, array $data);
68 69

  /**
70
   * Deletes a configuration object from the storage.
71
   *
72 73 74 75 76
   * @param string $name
   *   The name of a configuration object to delete.
   *
   * @return bool
   *   TRUE on success, FALSE otherwise.
77
   */
78
  public function delete($name);
gdd's avatar
gdd committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92
  /**
   * Renames a configuration object in the storage.
   *
   * @param string $name
   *   The name of a configuration object to rename.
   * @param string $new_name
   *   The new name of a configuration object.
   *
   * @return bool
   *   TRUE on success, FALSE otherwise.
   */
  public function rename($name, $new_name);

93 94
  /**
   * Encodes configuration data into the storage-specific format.
95 96 97 98 99 100 101 102 103
   *
   * @param array $data
   *   The configuration data to encode.
   *
   * @return string
   *   The encoded configuration data.
   *
   * This is a publicly accessible static method to allow for alternative
   * usages in data conversion scripts and also tests.
104
   */
105
  public function encode($data);
106 107 108

  /**
   * Decodes configuration data from the storage-specific format.
109 110 111 112 113 114 115 116 117
   *
   * @param string $raw
   *   The raw configuration data string to decode.
   *
   * @return array
   *   The decoded configuration data as an associative array.
   *
   * This is a publicly accessible static method to allow for alternative
   * usages in data conversion scripts and also tests.
118
   */
119
  public function decode($raw);
120

121 122 123 124 125 126 127
  /**
   * Gets configuration object names starting with a given prefix.
   *
   * Given the following configuration objects:
   * - node.type.article
   * - node.type.page
   *
128
   * Passing the prefix 'node.type.' will return an array containing the above
129 130 131 132 133 134 135 136 137
   * names.
   *
   * @param string $prefix
   *   (optional) The prefix to search for. If omitted, all configuration object
   *   names that exist are returned.
   *
   * @return array
   *   An array containing matching configuration object names.
   */
138
  public function listAll($prefix = '');
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

  /**
   * Deletes configuration objects whose names start with a given prefix.
   *
   * Given the following configuration object names:
   * - node.type.article
   * - node.type.page
   *
   * Passing the prefix 'node.type.' will delete the above configuration
   * objects.
   *
   * @param string $prefix
   *   (optional) The prefix to search for. If omitted, all configuration
   *   objects that exist will be deleted.
   *
   * @return boolean
   *   TRUE on success, FALSE otherwise.
   */
  public function deleteAll($prefix = '');

gdd's avatar
gdd committed
159
}