BootstrapConfigStorageFactory.php 1.6 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Config\BootstrapConfigStorageFactory.
6 7 8
 */

namespace Drupal\Core\Config;
9

10
use Drupal\Core\Database\Database;
11
use Drupal\Core\Site\Settings;
12 13 14 15 16 17 18 19 20

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

  /**
   * Returns a configuration storage implementation.
   *
21 22 23 24 25
   * @param $class_loader
   *   The class loader. Normally Composer's ClassLoader, as included by the
   *   front controller, but may also be decorated; e.g.,
   *   \Symfony\Component\ClassLoader\ApcClassLoader.
   *
26 27 28
   * @return \Drupal\Core\Config\StorageInterface
   *   A configuration storage implementation.
   */
29
  public static function get($class_loader = NULL) {
30
    $bootstrap_config_storage = Settings::get('bootstrap_config_storage');
31
    $storage_backend = FALSE;
32
    if (!empty($bootstrap_config_storage) && is_callable($bootstrap_config_storage)) {
33
      $storage_backend = call_user_func($bootstrap_config_storage, $class_loader);
34
    }
35
    // Fallback to the DatabaseStorage.
36
    return $storage_backend ?: self::getDatabaseStorage();
37 38 39 40 41 42 43 44 45
  }

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

48 49 50 51 52 53 54 55
  /**
   * 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));
  }
56
}