diff --git a/core/core.services.yml b/core/core.services.yml index 79f1fc1..17874b2 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -108,13 +108,13 @@ services: arguments: [default] keyvalue: class: Drupal\Core\KeyValueStore\KeyValueFactory - arguments: ['@service_container'] + arguments: ['@service_container', '@settings'] keyvalue.database: class: Drupal\Core\KeyValueStore\KeyValueDatabaseFactory arguments: ['@database'] keyvalue.expirable: class: Drupal\Core\KeyValueStore\KeyValueExpirableFactory - arguments: ['@service_container'] + arguments: ['@service_container', '@settings'] keyvalue.expirable.database: class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory tags: diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 91a241f..f3055c8 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2,6 +2,7 @@ use Drupal\Component\Utility\Crypt; +use Drupal\Component\Utility\Settings; use Drupal\Core\Config\FileStorage; use Drupal\Core\DrupalKernel; use Drupal\Core\CoreServiceProvider; @@ -422,14 +423,20 @@ function install_begin_request(&$install_state) { 'curl.CURLOPT_MAXREDIRS' => 3, )) ->addMethodCall('setUserAgent', array('Drupal (+http://drupal.org/)')); + $container->register('settings', 'Drupal\Component\Utility\Settings') + ->setFactoryClass('Drupal\Component\Utility\Settings') + ->setFactoryMethod('getSingleton'); // 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('service_container')) + ->addArgument(new Reference('settings')); $container ->register('keyvalue.expirable.null', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory'); - $conf['keyvalue_expirable_default'] = 'keyvalue.expirable.null'; + $settings = Settings::getSingleton()->getAll(); + $settings['keyvalue_expirable_default'] = 'keyvalue.expirable.null'; + new Settings($settings); // Register Twig template engine for use during install. CoreServiceProvider::registerTwig($container); diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php index 8747e53..4a7ca29 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueExpirableFactory.php @@ -14,30 +14,11 @@ */ class KeyValueExpirableFactory extends KeyValueFactory { - /** - * 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]; - } + const DEFAULT_SERVICE = 'keyvalue.expirable.database'; + + const SPECIFIC_PREFIX = 'keyvalue_expirable_service_'; + + const DEFAULT_SETTING = 'keyvalue_expirable_default'; + } diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php index 4e3f0a7..74ccd6e 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\KeyValueStore; +use Drupal\Component\Utility\Settings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -14,6 +15,29 @@ 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. * * @var array @@ -25,12 +49,22 @@ 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) { + function __construct(ContainerInterface $container, Settings $settings) { $this->container = $container; + $this->settings = $settings; } /** @@ -43,20 +77,18 @@ function __construct(ContainerInterface $container) { * A key/value store implementation for the given $collection. */ public function get($collection) { - global $conf; if (!isset($this->stores[$collection])) { - if (isset($conf['keyvalue_service_' . $collection])) { - $service_name = $conf['keyvalue_service_' . $collection]; + if ($service_name = $this->settings->get(static::SPECIFIC_PREFIX . $collection)) { } - elseif (isset($conf['keyvalue_default'])) { - $service_name = $conf['keyvalue_default']; + elseif ($service_name = $this->settings->get(static::DEFAULT_SETTING)) { } else { - $service_name = 'keyvalue.database'; + $service_name = static::DEFAULT_SERVICE; } $this->stores[$collection] = $this->container->get($service_name)->get($collection); } return $this->stores[$collection]; } + } diff --git a/core/lib/Drupal/Core/Path/AliasWhitelist.php b/core/lib/Drupal/Core/Path/AliasWhitelist.php index 0138644..9e3a6a1 100644 --- a/core/lib/Drupal/Core/Path/AliasWhitelist.php +++ b/core/lib/Drupal/Core/Path/AliasWhitelist.php @@ -11,7 +11,6 @@ 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; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 9b40ce5..656aebc 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -152,7 +152,7 @@ public function containerBuild(ContainerBuilder $container) { ->register('config.storage', 'Drupal\Core\Config\FileStorage') ->addArgument($this->configDirectories[CONFIG_ACTIVE_DIRECTORY]); - $conf['keyvalue_default'] = 'keyvalue.memory'; + $this->settingsSet('keyvalue_default', 'keyvalue.memory'); $container->set('keyvalue.memory', $this->keyValueFactory); if (!$container->has('keyvalue')) { // TestBase::setUp puts a completely empty container in @@ -165,9 +165,14 @@ 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('service_container')) + ->addArgument(new Reference('settings')); $container->register('state', 'Drupal\Core\KeyValueStore\KeyValueStoreInterface') ->setFactoryService(new Reference('keyvalue')) diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php index 9f4d01e..19a261b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php @@ -36,8 +36,7 @@ protected function setUp() { $this->container ->register('keyvalue.expirable.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory') ->addArgument(new Reference('database')); - global $conf; - $conf['keyvalue_expirable_default'] = 'keyvalue.expirable.database'; + $this->settingsSet('keyvalue_expirable_default', 'keyvalue.expirable.database'); } protected function tearDown() { diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php index 5f1f0ba..54471a7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/MemoryStorageTest.php @@ -31,22 +31,10 @@ 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']; } - $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(); + $this->settingsSet('keyvalue_default', 'keyvalue.memory'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php index 9bd2412..8ce534a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/StorageTestBase.php @@ -52,12 +52,17 @@ 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('service_container')) + ->addArgument(new Reference('settings')); $this->container ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueExpirableFactory') - ->addArgument(new Reference('service_container')); + ->addArgument(new Reference('service_container')) + ->addArgument(new Reference('settings')); // Define two data collections, $this->collections = array(0 => 'zero', 1 => 'one');