Pull merge.
[yaffs-website] / web / core / lib / Drupal / Core / Config / BootstrapConfigStorageFactory.php
1 <?php
2
3 namespace Drupal\Core\Config;
4
5 use Drupal\Core\Database\Database;
6 use Drupal\Core\Site\Settings;
7
8 /**
9  * Defines a factory for retrieving the config storage used pre-kernel.
10  */
11 class BootstrapConfigStorageFactory {
12
13   /**
14    * Returns a configuration storage implementation.
15    *
16    * @param $class_loader
17    *   The class loader. Normally Composer's ClassLoader, as included by the
18    *   front controller, but may also be decorated; e.g.,
19    *   \Symfony\Component\ClassLoader\ApcClassLoader.
20    *
21    * @return \Drupal\Core\Config\StorageInterface
22    *   A configuration storage implementation.
23    */
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    * Returns a Database configuration storage implementation.
36    *
37    * @return \Drupal\Core\Config\DatabaseStorage
38    */
39   public static function getDatabaseStorage() {
40     return new DatabaseStorage(Database::getConnection(), 'config');
41   }
42
43   /**
44    * Returns a File-based configuration storage implementation.
45    *
46    * If there is no active configuration directory calling this method will
47    * result in an error.
48    *
49    * @return \Drupal\Core\Config\FileStorage
50    *
51    * @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core
52    * no longer creates an active directory.
53    *
54    * @throws \Exception
55    */
56   public static function getFileStorage() {
57     return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
58   }
59
60 }