BootstrapConfigStorageFactory.php 1.78 KB
Newer Older
1 2 3
<?php

namespace Drupal\Core\Config;
4

5
use Drupal\Core\Database\Database;
6
use Drupal\Core\Site\Settings;
7 8 9 10 11 12 13 14 15

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

  /**
   * Returns a configuration storage implementation.
   *
16 17 18 19 20
   * @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.
   *
21 22 23
   * @return \Drupal\Core\Config\StorageInterface
   *   A configuration storage implementation.
   */
24
  public static function get($class_loader = NULL) {
25
    $bootstrap_config_storage = Settings::get('bootstrap_config_storage');
26
    $storage_backend = FALSE;
27
    if (!empty($bootstrap_config_storage) && is_callable($bootstrap_config_storage)) {
28
      $storage_backend = call_user_func($bootstrap_config_storage, $class_loader);
29
    }
30
    // Fallback to the DatabaseStorage.
31
    return $storage_backend ?: self::getDatabaseStorage();
32 33 34 35 36 37 38 39 40
  }

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

43 44 45
  /**
   * Returns a File-based configuration storage implementation.
   *
46 47 48
   * If there is no active configuration directory calling this method will
   * result in an error.
   *
49
   * @return \Drupal\Core\Config\FileStorage
50 51 52 53 54
   *
   * @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core
   * no longer creates an active directory.
   *
   * @throws \Exception
55 56 57 58
   */
  public static function getFileStorage() {
    return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
  }
59

60
}