BootstrapConfigStorageFactory.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\Config;
  3. use Drupal\Core\Database\Database;
  4. use Drupal\Core\Site\Settings;
  5. /**
  6. * Defines a factory for retrieving the config storage used pre-kernel.
  7. */
  8. class BootstrapConfigStorageFactory {
  9. /**
  10. * Returns a configuration storage implementation.
  11. *
  12. * @param $class_loader
  13. * The class loader. Normally Composer's ClassLoader, as included by the
  14. * front controller, but may also be decorated; e.g.,
  15. * \Symfony\Component\ClassLoader\ApcClassLoader.
  16. *
  17. * @return \Drupal\Core\Config\StorageInterface
  18. * A configuration storage implementation.
  19. */
  20. public static function get($class_loader = NULL) {
  21. $bootstrap_config_storage = Settings::get('bootstrap_config_storage');
  22. $storage_backend = FALSE;
  23. if (!empty($bootstrap_config_storage) && is_callable($bootstrap_config_storage)) {
  24. $storage_backend = call_user_func($bootstrap_config_storage, $class_loader);
  25. }
  26. // Fallback to the DatabaseStorage.
  27. return $storage_backend ?: self::getDatabaseStorage();
  28. }
  29. /**
  30. * Returns a Database configuration storage implementation.
  31. *
  32. * @return \Drupal\Core\Config\DatabaseStorage
  33. */
  34. public static function getDatabaseStorage() {
  35. return new DatabaseStorage(Database::getConnection(), 'config');
  36. }
  37. /**
  38. * Returns a File-based configuration storage implementation.
  39. *
  40. * If there is no active configuration directory calling this method will
  41. * result in an error.
  42. *
  43. * @return \Drupal\Core\Config\FileStorage
  44. *
  45. * @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core
  46. * no longer creates an active directory.
  47. *
  48. * @throws \Exception
  49. */
  50. public static function getFileStorage() {
  51. return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
  52. }
  53. }