summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php
blob: 2462eaf74ef169f13c9cbe2465fe8497618dfe5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

/**
 * @file
 * Contains Drupal\Core\Config\BootstrapConfigStorageFactory.
 */

namespace Drupal\Core\Config;

use Drupal\Core\Database\Database;
use Drupal\Core\Site\Settings;

/**
 * Defines a factory for retrieving the config storage used pre-kernel.
 */
class BootstrapConfigStorageFactory {

  /**
   * Returns a configuration storage implementation.
   *
   * @return \Drupal\Core\Config\StorageInterface
   *   A configuration storage implementation.
   */
  public static function get() {
    $bootstrap_config_storage = Settings::get('bootstrap_config_storage');
    if (!empty($bootstrap_config_storage) && is_callable($bootstrap_config_storage)) {
      return call_user_func($bootstrap_config_storage);
    }
    // Fallback to the DatabaseStorage.
    return self::getDatabaseStorage();
  }

  /**
   * Returns a Database configuration storage implementation.
   *
   * @return \Drupal\Core\Config\DatabaseStorage
   */
  public static function getDatabaseStorage() {
    return new DatabaseStorage(Database::getConnection(), 'config');
  }

  /**
   * Returns a File-based configuration storage implementation.
   *
   * @return \Drupal\Core\Config\FileStorage
   */
  public static function getFileStorage() {
    return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
  }
}