Commit 5b6f9d79 authored by Dries's avatar Dries

- Issue #2156265 by sun: KeyValueFactory is swappable, add an interface and fix type-hints.

parent 03f4982c
......@@ -437,24 +437,11 @@ function install_begin_request(&$install_state) {
$container->register('settings', 'Drupal\Component\Utility\Settings')
->setFactoryClass('Drupal\Component\Utility\Settings')
->setFactoryMethod('getSingleton');
$container->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory')
->addArgument(new Reference('service_container'))
->addArgument(new Reference('settings'));
// Register the expirable key value store used by form cache.
$container
->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory')
->addArgument(new Reference('service_container'))
->addArgument(new Reference('settings'));
$container->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
$container
->register('keyvalue.expirable.null', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory');
$settings = Settings::getSingleton()->getAll();
$settings['settings_old'] = $settings;
$settings['keyvalue_expirable_default'] = 'keyvalue.expirable.null';
// Override the default keyvalue storage to use memory as the database is
// not available.
$settings['keyvalue_default'] = 'keyvalue.memory';
new Settings($settings);
->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory');
$container->register('state', 'Drupal\Core\KeyValueStore\State')
->addArgument(new Reference('keyvalue'));
......@@ -1297,11 +1284,6 @@ function install_settings_form_submit($form, &$form_state) {
// Add the config directories to settings.php.
drupal_install_config_directories($install_state['mode']);
// The container is about to be rebuilt so we need to unset the keyvalue
// storage override that the installer is using.
$settings = Settings::getSingleton()->getAll();
new Settings($settings['settings_old']);
// Indicate that the settings file has been verified, and check the database
// for the last completed task, now that we have a valid connection. This
// last step is important since we want to trigger an error if the new
......
......@@ -15,6 +15,7 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\HttpKernel;
use Drupal\Core\KeyValueStore\KeyValueExpirableFactory;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
......@@ -41,7 +42,7 @@ class FormBuilder implements FormBuilderInterface {
/**
* The factory for expirable key value stores used by form cache.
*
* @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactory
* @var \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
*/
protected $keyValueExpirableFactory;
......@@ -123,7 +124,7 @@ class FormBuilder implements FormBuilderInterface {
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactory $key_value_expirable_factory
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_expirable_factory
* The keyvalue expirable factory.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
......@@ -136,7 +137,7 @@ class FormBuilder implements FormBuilderInterface {
* @param \Drupal\Core\HttpKernel $http_kernel
* The HTTP kernel.
*/
public function __construct(ModuleHandlerInterface $module_handler, KeyValueExpirableFactory $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $translation_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) {
public function __construct(ModuleHandlerInterface $module_handler, KeyValueFactoryInterface $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $translation_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) {
$this->moduleHandler = $module_handler;
$this->keyValueExpirableFactory = $key_value_expirable_factory;
$this->eventDispatcher = $event_dispatcher;
......
......@@ -25,15 +25,7 @@ class KeyValueDatabaseExpirableFactory extends KeyValueDatabaseFactory implement
protected $storages;
/**
* Constructs a new key/value expirable database storage object for a given
* collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
* @param \Drupal\Core\Database\Connection $connection
* The connection to run against.
* @return \Drupal\Core\KeyValueStore\DatabaseStorageExpirable
* A key/value store implementation for the given $collection.
* {@inheritdoc}
*/
public function get($collection) {
$storage = new DatabaseStorageExpirable($collection, $this->connection);
......
......@@ -12,7 +12,7 @@
/**
* Defines the key/value store factory for the database backend.
*/
class KeyValueDatabaseFactory {
class KeyValueDatabaseFactory implements KeyValueFactoryInterface {
/**
* Constructs this factory object.
......@@ -26,14 +26,7 @@ function __construct(Connection $connection) {
}
/**
* Constructs a new key/value database storage object for a given collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
* @param \Drupal\Core\Database\Connection $connection
* The connection to run against.
* @return \Drupal\Core\KeyValueStore\DatabaseStorage
* A key/value store implementation for the given $collection.
* {@inheritdoc}
*/
public function get($collection) {
return new DatabaseStorage($collection, $this->connection);
......
......@@ -12,7 +12,7 @@
/**
* Defines the key/value store factory.
*/
class KeyValueFactory {
class KeyValueFactory implements KeyValueFactoryInterface {
/**
* The specific setting name prefix.
......@@ -68,13 +68,7 @@ function __construct(ContainerInterface $container, Settings $settings) {
}
/**
* Constructs a new key/value store for a given collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
*
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
* A key/value store implementation for the given $collection.
* {@inheritdoc}
*/
public function get($collection) {
if (!isset($this->stores[$collection])) {
......
<?php
/**
* @file
* Contains \Drupal\Core\KeyValueStore\KeyValueFactoryInterface.
*/
namespace Drupal\Core\KeyValueStore;
/**
* Defines the key/value store factory interface.
*/
interface KeyValueFactoryInterface {
/**
* Constructs a new key/value store for a given collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
*
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
* A key/value store implementation for the given $collection.
*/
public function get($collection);
}
......@@ -10,7 +10,7 @@
/**
* Defines the key/value store factory for the database backend.
*/
class KeyValueMemoryFactory {
class KeyValueMemoryFactory implements KeyValueFactoryInterface {
/**
* An array of keyvalue collections that are stored in memory.
......@@ -20,12 +20,7 @@ class KeyValueMemoryFactory {
protected $collections = array();
/**
* Constructs a new key/value memory storage object for a given collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
* @return \Drupal\Core\KeyValueStore\MemoryStorage
* A key/value store implementation for the given $collection.
* {@inheritdoc}
*/
public function get($collection) {
if (!isset($this->collections[$collection])) {
......
......@@ -10,17 +10,10 @@
/**
* Defines the key/value store factory for the null backend.
*/
class KeyValueNullExpirableFactory {
class KeyValueNullExpirableFactory implements KeyValueFactoryInterface {
/**
* Constructs a new key/value expirable null storage object for a given
* collection name.
*
* @param string $collection
* The name of the collection holding key and value pairs.
*
* @return \Drupal\Core\KeyValueStore\DatabaseStorageExpirable
* A key/value store implementation for the given $collection.
* {@inheritdoc}
*/
public function get($collection) {
return new NullStorageExpirable($collection);
......
......@@ -29,10 +29,10 @@ class State implements StateInterface {
/**
* Constructs a State object.
*
* @param \Drupal\Core\KeyValueStore\KeyValueFactory $key_value_factory
* The key value store to use.
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
* The key value store to use.
*/
function __construct(KeyValueFactory $key_value_factory) {
function __construct(KeyValueFactoryInterface $key_value_factory) {
$this->keyValueStore = $key_value_factory->get('state');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment