Commit 085ad457 authored by alexpott's avatar alexpott

Revert "Fixing commit message: Change KeyValueFactory to use Settings instead of $conf"

This reverts commit 227f21b3.
parent 709e3044
......@@ -108,13 +108,13 @@ services:
arguments: [default]
keyvalue:
class: Drupal\Core\KeyValueStore\KeyValueFactory
arguments: ['@service_container', '@settings']
arguments: ['@service_container']
keyvalue.database:
class: Drupal\Core\KeyValueStore\KeyValueDatabaseFactory
arguments: ['@database']
keyvalue.expirable:
class: Drupal\Core\KeyValueStore\KeyValueExpirableFactory
arguments: ['@service_container', '@settings']
arguments: ['@service_container']
keyvalue.expirable.database:
class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
tags:
......
......@@ -2,7 +2,6 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Settings;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\DrupalKernel;
use Drupal\Core\CoreServiceProvider;
......@@ -292,6 +291,9 @@ function install_begin_request(&$install_state) {
// A request object from the HTTPFoundation to tell us about the request.
$request = Request::createFromGlobals();
// This must go after drupal_bootstrap(), which unsets globals!
global $conf;
// If we have a language selected and it is not yet saved in the system
// (eg. pre-database data screens we are unable to persistently store
// the default language), we should set language_default so the proper
......@@ -421,27 +423,20 @@ function install_begin_request(&$install_state) {
))
->addMethodCall('setUserAgent', array('Drupal (+http://drupal.org/)'));
$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'));
->addArgument(new Reference('service_container'));
$container->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
// Override the default keyvalue storage to use memory as the database is
// not available.
$conf['keyvalue_default'] = 'keyvalue.memory';
// 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');
->addArgument(new Reference('service_container'));
$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);
$conf['keyvalue_expirable_default'] = 'keyvalue.expirable.null';
$container->register('state', 'Drupal\Core\KeyValueStore\KeyValueStoreInterface')
->setFactoryService(new Reference('keyvalue'))
......@@ -1272,8 +1267,7 @@ function install_settings_form_submit($form, &$form_state) {
// 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']);
unset($conf['keyvalue_default']);
// 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
......
......@@ -14,11 +14,30 @@
*/
class KeyValueExpirableFactory extends KeyValueFactory {
const DEFAULT_SERVICE = 'keyvalue.expirable.database';
const SPECIFIC_PREFIX = 'keyvalue_expirable_service_';
const DEFAULT_SETTING = 'keyvalue_expirable_default';
/**
* Constructs a new expirable 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\KeyValueStoreExpirableInterface
* An expirable key/value store implementation for the given $collection.
*/
public function get($collection) {
global $conf;
if (!isset($this->stores[$collection])) {
if (isset($conf['keyvalue_expirable_service_' . $collection])) {
$service_name = $conf['keyvalue_expirable_service_' . $collection];
}
elseif (isset($conf['keyvalue_expirable_default'])) {
$service_name = $conf['keyvalue_expirable_default'];
}
else {
$service_name = 'keyvalue.expirable.database';
}
$this->stores[$collection] = $this->container->get($service_name)->get($collection);
}
return $this->stores[$collection];
}
}
......@@ -6,7 +6,6 @@
*/
namespace Drupal\Core\KeyValueStore;
use Drupal\Component\Utility\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -14,29 +13,6 @@
*/
class KeyValueFactory {
/**
* The specific setting name prefix.
*
* The collection name will be prefixed with this constant and used as a
* setting name. The setting value will be the id of a service.
*/
const SPECIFIC_PREFIX = 'keyvalue_service_';
/**
* The default setting name.
*
* This is a setting name that will be used if the specific setting does not
* exist. The setting value will be the id of a service.
*/
const DEFAULT_SETTING = 'keyvalue_default';
/**
* The default service id.
*
* If the default setting does not exist, this is the default service id.
*/
const DEFAULT_SERVICE = 'keyvalue.database';
/**
* Instantiated stores, keyed by collection name.
*
......@@ -49,22 +25,12 @@ class KeyValueFactory {
*/
protected $container;
/**
* The read-only settings container.
*
* @var \Drupal\Component\Utility\Settings
*/
protected $settings;
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
* @param \Drupal\Component\Utility\Settings $settings
* The read-only settings container.
*/
function __construct(ContainerInterface $container, Settings $settings) {
function __construct(ContainerInterface $container) {
$this->container = $container;
$this->settings = $settings;
}
/**
......@@ -77,18 +43,20 @@ function __construct(ContainerInterface $container, Settings $settings) {
* A key/value store implementation for the given $collection.
*/
public function get($collection) {
global $conf;
if (!isset($this->stores[$collection])) {
if ($service_name = $this->settings->get(static::SPECIFIC_PREFIX . $collection)) {
if (isset($conf['keyvalue_service_' . $collection])) {
$service_name = $conf['keyvalue_service_' . $collection];
}
elseif ($service_name = $this->settings->get(static::DEFAULT_SETTING)) {
elseif (isset($conf['keyvalue_default'])) {
$service_name = $conf['keyvalue_default'];
}
else {
$service_name = static::DEFAULT_SERVICE;
$service_name = 'keyvalue.database';
}
$this->stores[$collection] = $this->container->get($service_name)->get($collection);
}
return $this->stores[$collection];
}
}
......@@ -11,6 +11,7 @@
use Drupal\Core\Cache\CacheCollector;
use Drupal\Core\Database\Connection;
use Drupal\Core\DestructableInterface;
use Drupal\Core\KeyValueStore\KeyValueFactory;
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Utility\CacheArray;
......
......@@ -152,7 +152,7 @@ public function containerBuild(ContainerBuilder $container) {
->register('config.storage', 'Drupal\Core\Config\FileStorage')
->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]);
$this->settingsSet('keyvalue_default', 'keyvalue.memory');
$conf['keyvalue_default'] = 'keyvalue.memory';
$container->set('keyvalue.memory', $this->keyValueFactory);
if (!$container->has('keyvalue')) {
// TestBase::setUp puts a completely empty container in
......@@ -165,14 +165,9 @@ public function containerBuild(ContainerBuilder $container) {
// together here, it still might a keyvalue storage for anything using
// \Drupal::state() -- that's why a memory service was added in the first
// place.
$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'));
->addArgument(new Reference('service_container'));
$container->register('state', 'Drupal\Core\KeyValueStore\KeyValueStoreInterface')
->setFactoryService(new Reference('keyvalue'))
......
......@@ -36,7 +36,8 @@ protected function setUp() {
$this->container
->register('keyvalue.expirable.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory')
->addArgument(new Reference('database'));
$this->settingsSet('keyvalue_expirable_default', 'keyvalue.expirable.database');
global $conf;
$conf['keyvalue_expirable_default'] = 'keyvalue.expirable.database';
}
protected function tearDown() {
......
......@@ -31,10 +31,22 @@ protected function setUp() {
parent::setUp();
$this->container
->register('keyvalue.memory', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
global $conf;
if (isset($conf['keyvalue_default'])) {
$this->originalKeyValue = $conf['keyvalue_default'];
}
$this->settingsSet('keyvalue_default', 'keyvalue.memory');
$conf['keyvalue_default'] = 'keyvalue.memory';
}
protected function tearDown() {
global $conf;
if (isset($this->originalKeyValue)) {
$conf['keyvalue_default'] = $this->originalKeyValue;
}
else {
unset($conf['keyvalue_default']);
}
parent::tearDown();
}
}
......@@ -52,17 +52,12 @@ protected function setUp() {
->register('service_container', 'Symfony\Component\DependencyInjection\ContainerBuilder')
->setSynthetic(TRUE);
$this->container->set('service_container', $this->container);
$this->container->register('settings', 'Drupal\Component\Utility\Settings')
->setFactoryClass('Drupal\Component\Utility\Settings')
->setFactoryMethod('getSingleton');
$this->container
->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory')
->addArgument(new Reference('service_container'))
->addArgument(new Reference('settings'));
->addArgument(new Reference('service_container'));
$this->container
->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory')
->addArgument(new Reference('service_container'))
->addArgument(new Reference('settings'));
->addArgument(new Reference('service_container'));
// Define two data collections,
$this->collections = array(0 => 'zero', 1 => 'one');
......
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