diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 7daf311..5e31f03 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2437,26 +2437,21 @@ function drupal_container(Container $reset = NULL) { // This will get merged with the full Kernel-built Container on normal page // requests. $container = new ContainerBuilder(); - // Register configuration storage dispatcher. - $container->setParameter('config.storage.info', array( - 'Drupal\Core\Config\DatabaseStorage' => array( - 'connection' => 'default', - 'target' => 'default', - 'read' => TRUE, - 'write' => TRUE, - ), - 'Drupal\Core\Config\FileStorage' => array( - 'directory' => config_get_config_directory(), - 'read' => TRUE, - 'write' => FALSE, - ), + // Register configuration storage class and options. + // @todo The active store and its options need to be configurable. + // Use either global $conf (recursion warning) or global $config, or a + // bootstrap configuration *file* to allow to set/override this very + // lowest of low level configuration. + $this->setParameter('config.storage.options', array( + 'connection' => 'default', + 'target' => 'default', )); - $container->register('config.storage.dispatcher', 'Drupal\Core\Config\StorageDispatcher') - ->addArgument('%config.storage.info%'); + $this->register('config.storage', 'Drupal\Core\Config\DatabaseStorage') + ->addArgument('%config.storage.options%'); // Register configuration object factory. $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') - ->addArgument(new Reference('config.storage.dispatcher')); + ->addArgument(new Reference('config.storage')); } return $container; } diff --git a/core/includes/config.inc b/core/includes/config.inc index 5b1fe21..9fd4a1b 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -185,7 +185,7 @@ function config_import() { * @todo Add support for other extension types; e.g., themes etc. */ function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { - $storage_dispatcher = drupal_container()->get('config.storage.dispatcher'); + $storage = drupal_container()->get('config.storage'); // Allow modules to take over configuration change operations for // higher-level configuration data. @@ -199,13 +199,13 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou // handle the configuration change. $handled_by_module = FALSE; if (module_hook($module, 'config_import_' . $op)) { - $old_config = new Config($storage_dispatcher); + $old_config = new Config($storage); $old_config ->setName($name) ->load(); $data = $source_storage->read($name); - $new_config = new Config($storage_dispatcher); + $new_config = new Config($storage); $new_config->setName($name); if ($data !== FALSE) { $new_config->setData($data); diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index ffddd61..2f4d14a 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -36,21 +36,21 @@ class Config { protected $data = array(); /** - * The injected storage dispatcher object. + * The storage used for reading and writing. * - * @var Drupal\Core\Config\StorageDispatcher + * @var Drupal\Core\Config\StorageInterface */ - protected $storageDispatcher; + protected $storage; /** * Constructs a configuration object. * - * @param Drupal\Core\Config\StorageDispatcher $storageDispatcher - * A storage dispatcher object to use for reading and writing the + * @param Drupal\Core\Config\StorageInterface $storage + * A storage controller object to use for reading and writing the * configuration data. */ - public function __construct(StorageDispatcher $storageDispatcher) { - $this->storageDispatcher = $storageDispatcher; + public function __construct(StorageInterface $storage) { + $this->storage = $storage; } /** @@ -224,7 +224,7 @@ class Config { * Loads configuration data into this object. */ public function load() { - $data = $this->storageDispatcher->selectStorage('read', $this->name)->read($this->name); + $data = $this->storage->read($this->name); if ($data === FALSE) { $this->isNew = TRUE; $this->setData(array()); @@ -241,7 +241,7 @@ class Config { */ public function save() { $this->sortByKey($this->data); - $this->storageDispatcher->selectStorage('write', $this->name)->write($this->name, $this->data); + $this->storage->write($this->name, $this->data); $this->isNew = FALSE; return $this; } @@ -271,7 +271,7 @@ class Config { */ public function delete() { $this->data = array(); - $this->storageDispatcher->selectStorage('write', $this->name)->delete($this->name); + $this->storage->delete($this->name); $this->isNew = TRUE; return $this; } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 1fbca62..7c26b6e 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -15,29 +15,29 @@ namespace Drupal\Core\Config; * * @see Drupal\Core\Config\Config * - * Each configuration object gets a storage dispatcher object injected, which - * determines the storage controller to use for reading and writing the - * configuration data. + * Each configuration object gets a storage controller object injected, which + * is used for reading and writing the configuration data. * - * @see Drupal\Core\Config\StorageDispatcher + * @see Drupal\Core\Config\StorageInterface */ class ConfigFactory { + /** - * A storage dispatcher instance to use for reading and writing configuration data. + * A storage controller instance for reading and writing configuration data. * - * @var Drupal\Core\Config\StorageDispatcher + * @var Drupal\Core\Config\StorageInterface */ - protected $storageDispatcher; + protected $storage; /** * Constructs the Config factory. * - * @param Drupal\Core\Config\StorageDispatcher $storage_dispatcher - * The storage dispatcher object to use for reading and writing + * @param Drupal\Core\Config\StorageInterface $storage + * The storage controller object to use for reading and writing * configuration data. */ - public function __construct(StorageDispatcher $storage_dispatcher) { - $this->storageDispatcher = $storage_dispatcher; + public function __construct(StorageInterface $storage) { + $this->storage = $storage; } /** @@ -68,7 +68,8 @@ class ConfigFactory { // @todo The decrease of CPU time is interesting, since that means that // ContainerBuilder involves plenty of function calls (which are known to // be slow in PHP). - $config = new Config($this->storageDispatcher); + $config = new Config($this->storage); return $config->setName($name); } + } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index f30011c..92aea45 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -56,8 +56,8 @@ class DatabaseStorage implements StorageInterface { // read without actually having the database available. In this case, // catch the exception and just return an empty array so the caller can // handle it if need be. - // @todo Remove this and use appropriate StorageDispatcher configuration in - // the installer instead. + // @todo Remove this and use appropriate config.storage service definition + // in the installer instead. try { $raw = $this->getConnection()->query('SELECT data FROM {config} WHERE name = :name', array(':name' => $name), $this->options)->fetchField(); if ($raw !== FALSE) { diff --git a/core/lib/Drupal/Core/Config/StorageDispatcher.php b/core/lib/Drupal/Core/Config/StorageDispatcher.php deleted file mode 100644 index ebf7049..0000000 --- a/core/lib/Drupal/Core/Config/StorageDispatcher.php +++ /dev/null @@ -1,105 +0,0 @@ - array( - * 'target' => 'default', - * 'read' => TRUE, - * 'write' => TRUE, - * ), - * 'Drupal\Core\Config\FileStorage' => array( - * 'directory' => 'sites/default/files/config', - * 'read' => TRUE, - * 'write' => FALSE, - * ), - * ) - * @endcode - */ - public function __construct(array $storage_info) { - $this->storageInfo = $storage_info; - } - - /** - * Returns a storage controller to use for a given operation. - * - * Handles the core functionality of the storage dispatcher by determining - * which storage can handle a particular storage access operation and - * configuration object. - * - * @param string $access_operation - * The operation access level; either 'read' or 'write'. Use 'write' both - * for saving and deleting configuration. - * @param string $name - * The name of the configuration object that is operated on. - * - * @return Drupal\Core\Config\StorageInterface - * The storage controller instance that can handle the requested operation. - * - * @throws Drupal\Core\Config\ConfigException - * - * @todo Allow write operations to write to multiple storages. - */ - public function selectStorage($access_operation, $name) { - // Determine the appropriate storage controller to use. - // Take the first defined storage that allows $op. - foreach ($this->storageInfo as $class => $storage_config) { - if (!empty($storage_config[$access_operation])) { - $storage_class = $class; - break; - } - } - if (!isset($storage_class)) { - throw new ConfigException("Failed to find storage controller that allows $access_operation access for $name."); - } - - // Instantiate a new storage controller object, if there is none yet. - if (!isset($this->storageInstances[$storage_class])) { - $this->storageInstances[$storage_class] = new $storage_class($this->storageInfo[$storage_class]); - } - return $this->storageInstances[$storage_class]; - } -}