Issue #2216527 by sun: Inject a serialization format into database key/value storage.
[project/drupal.git] / core / lib / Drupal / Core / Config / BootstrapConfigStorageFactory.php
1 <?php
2
3 /**
4 * @file
5 * Contains Drupal\Core\Config\BootstrapConfigStorageFactory.
6 */
7
8 namespace Drupal\Core\Config;
9
10 use Drupal\Core\Database\Database;
11 use Drupal\Component\Utility\Settings;
12
13 /**
14 * Defines a factory for retrieving the config storage used pre-kernel.
15 */
16 class BootstrapConfigStorageFactory {
17
18 /**
19 * Returns a configuration storage implementation.
20 *
21 * @return \Drupal\Core\Config\StorageInterface
22 * A configuration storage implementation.
23 */
24 public static function get() {
25 $bootstrap_config_storage = Settings::get('bootstrap_config_storage');
26 if (!empty($bootstrap_config_storage) && is_callable($bootstrap_config_storage)) {
27 return call_user_func($bootstrap_config_storage);
28 }
29 // Fallback to the DatabaseStorage.
30 return self::getDatabaseStorage();
31 }
32
33 /**
34 * Returns a Database configuration storage implementation.
35 *
36 * @return \Drupal\Core\Config\DatabaseStorage
37 */
38 public static function getDatabaseStorage() {
39 return new DatabaseStorage(Database::getConnection(), 'config');
40 }
41
42 /**
43 * Returns a File-based configuration storage implementation.
44 *
45 * @return \Drupal\Core\Config\FileStorage
46 */
47 public static function getFileStorage() {
48 return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
49 }
50 }