diff --git a/core/core.services.yml b/core/core.services.yml index 20b8651..a1de04c 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -137,10 +137,10 @@ services: factory_class: Drupal\Component\Utility\Settings factory_method: getSingleton state: - class: Drupal\Core\KeyValueStore\KeyValueStoreInterface - factory_method: get - factory_service: keyvalue - arguments: [state] + class: Drupal\Core\KeyValueStore\State + arguments: ['@keyvalue'] + tags: + - { name: persist } queue: class: Drupal\Core\Queue\QueueFactory arguments: ['@settings'] diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index f53b788..417a2cc 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -453,10 +453,8 @@ function install_begin_request(&$install_state) { $settings['keyvalue_default'] = 'keyvalue.memory'; new Settings($settings); - $container->register('state', 'Drupal\Core\KeyValueStore\KeyValueStoreInterface') - ->setFactoryService(new Reference('keyvalue')) - ->setFactoryMethod('get') - ->addArgument('state'); + $container->register('state', 'Drupal\Core\KeyValueStore\State') + ->addArgument(new Reference('keyvalue')); // Register Twig template engine for use during install. CoreServiceProvider::registerTwig($container); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index a03ee24..5441e30 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -288,7 +288,7 @@ public static function keyValue($collection) { * needs to be the same across development, production, etc. environments * (for example, the system maintenance message) should use \Drupal::config() instead. * - * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @return \Drupal\Core\KeyValueStore\StateInterface */ public static function state() { return static::$container->get('state'); diff --git a/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php index 5d43231..22a4a5e 100644 --- a/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/CssCollectionOptimizer.php @@ -6,8 +6,7 @@ namespace Drupal\Core\Asset; -use Drupal\Core\Asset\AssetCollectionOptimizerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** * Optimizes CSS assets. @@ -38,7 +37,7 @@ class CssCollectionOptimizer implements AssetCollectionOptimizerInterface { /** * The state key/value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -51,10 +50,10 @@ class CssCollectionOptimizer implements AssetCollectionOptimizerInterface { * The optimizer for a single CSS asset. * @param \Drupal\Core\Asset\AssetDumperInterface * The dumper for optimized CSS assets. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @param \Drupal\Core\KeyValueStore\StateInterface * The state key/value store. */ - public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, KeyValueStoreInterface $state) { + public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state) { $this->grouper = $grouper; $this->optimizer = $optimizer; $this->dumper = $dumper; diff --git a/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php b/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php index 09846c1..e1cb3cd 100644 --- a/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/CssCollectionRenderer.php @@ -6,9 +6,8 @@ namespace Drupal\Core\Asset; -use Drupal\Core\Asset\AssetCollectionRendererInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Component\Utility\String; +use Drupal\Core\KeyValueStore\StateInterface; /** * Renders CSS assets. @@ -18,17 +17,17 @@ class CssCollectionRenderer implements AssetCollectionRendererInterface { /** * The state key/value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; /** * Constructs a CssCollectionRenderer. * - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @param \Drupal\Core\KeyValueStore\StateInterface * The state key/value store. */ - public function __construct(KeyValueStoreInterface $state) { + public function __construct(StateInterface $state) { $this->state = $state; } diff --git a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php index bf4cbf6..4d39a2e 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionOptimizer.php @@ -6,8 +6,7 @@ namespace Drupal\Core\Asset; -use Drupal\Core\Asset\AssetCollectionOptimizerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** @@ -39,7 +38,7 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface { /** * The state key/value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -52,10 +51,10 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface { * The optimizer for a single JS asset. * @param \Drupal\Core\Asset\AssetDumperInterface * The dumper for optimized JS assets. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @param \Drupal\Core\KeyValueStore\StateInterface * The state key/value store. */ - public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, KeyValueStoreInterface $state) { + public function __construct(AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state) { $this->grouper = $grouper; $this->optimizer = $optimizer; $this->dumper = $dumper; diff --git a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php index 443387a..b9de5f8 100644 --- a/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php +++ b/core/lib/Drupal/Core/Asset/JsCollectionRenderer.php @@ -6,8 +6,7 @@ namespace Drupal\Core\Asset; -use Drupal\Core\Asset\AssetCollectionRendererInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** * Renders JavaScript assets. @@ -17,17 +16,17 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface { /** * The state key/value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; /** * Constructs a CssCollectionRenderer. * - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @param \Drupal\Core\KeyValueStore\StateInterface * The state key/value store. */ - public function __construct(KeyValueStoreInterface $state) { + public function __construct(StateInterface $state) { $this->state = $state; } diff --git a/core/lib/Drupal/Core/Extension/CachedModuleHandler.php b/core/lib/Drupal/Core/Extension/CachedModuleHandler.php index 6e09432..0def7f3 100644 --- a/core/lib/Drupal/Core/Extension/CachedModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/CachedModuleHandler.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Extension; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** * Class that manages enabled modules in a Drupal installation. @@ -18,7 +18,7 @@ class CachedModuleHandler extends ModuleHandler implements CachedModuleHandlerIn /** * State key/value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -39,7 +39,7 @@ class CachedModuleHandler extends ModuleHandler implements CachedModuleHandlerIn /** * Constructs a new CachedModuleHandler object. */ - public function __construct(array $module_list = array(), KeyValueStoreInterface $state, CacheBackendInterface $bootstrap_cache) { + public function __construct(array $module_list = array(), StateInterface $state, CacheBackendInterface $bootstrap_cache) { parent::__construct($module_list); $this->state = $state; $this->bootstrapCache = $bootstrap_cache; diff --git a/core/lib/Drupal/Core/KeyValueStore/State.php b/core/lib/Drupal/Core/KeyValueStore/State.php new file mode 100644 index 0000000..9a7d7aa --- /dev/null +++ b/core/lib/Drupal/Core/KeyValueStore/State.php @@ -0,0 +1,124 @@ +keyValueStore = $key_value_factory->get('state'); + } + + /** + * {@inheritdoc} + */ + public function get($key, $default = NULL) { + $values = $this->getMultiple(array($key)); + return isset($values[$key]) ? $values[$key] : $default; + } + + /** + * {@inheritdoc} + */ + public function getMultiple(array $keys) { + $values = array(); + $load = array(); + foreach ($keys as $key) { + // Check if we have a value in the cache. + if (isset($this->cache[$key])) { + $values[$key] = $this->cache[$key]; + } + // Load the value if we don't have an explicit NULL value. + elseif (!array_key_exists($key, $this->cache)) { + $load[] = $key; + } + } + + if ($load) { + $loaded_values = $this->keyValueStore->getMultiple($load); + foreach ($load as $key) { + // If we find a value, even one that is NULL, add it to the cache and + // return it. + if (isset($loaded_values[$key]) || array_key_exists($key, $loaded_values)) { + $values[$key] = $loaded_values[$key]; + $this->cache[$key] = $loaded_values[$key]; + } + else { + $this->cache[$key] = NULL; + } + } + } + + return $values; + } + + /** + * {@inheritdoc} + */ + public function set($key, $value) { + $this->cache[$key] = $value; + $this->keyValueStore->set($key, $value); + } + + /** + * {@inheritdoc} + */ + public function setMultiple(array $data) { + foreach ($data as $key => $value) { + $this->cache[$key] = $value; + } + $this->keyValueStore->setMultiple($data); + } + + /** + * {@inheritdoc} + */ + public function delete($key) { + $this->deleteMultiple(array($key)); + } + + /** + * {@inheritdoc} + */ + public function deleteMultiple(array $keys) { + foreach ($keys as $key) { + unset($this->cache[$key]); + } + $this->keyValueStore->deleteMultiple($keys); + } + + /** + * {@inheritdoc} + */ + public function resetCache() { + $this->cache = array(); + } + +} diff --git a/core/lib/Drupal/Core/KeyValueStore/StateInterface.php b/core/lib/Drupal/Core/KeyValueStore/StateInterface.php new file mode 100644 index 0000000..f5f3da6 --- /dev/null +++ b/core/lib/Drupal/Core/KeyValueStore/StateInterface.php @@ -0,0 +1,80 @@ +state = $state; $this->moduleHandler = $module_handler; } diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index 72e5707..151bb23 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -21,13 +21,6 @@ class AliasManager implements AliasManagerInterface { protected $connection; /** - * The Key/Value Store to use for state - * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface - */ - protected $state; - - /** * Language manager for retrieving the default langcode when none is specified. * * @var \Drupal\Core\Language\LanguageManager diff --git a/core/lib/Drupal/Core/Path/AliasWhitelist.php b/core/lib/Drupal/Core/Path/AliasWhitelist.php index 9e3a6a1..2c151b5 100644 --- a/core/lib/Drupal/Core/Path/AliasWhitelist.php +++ b/core/lib/Drupal/Core/Path/AliasWhitelist.php @@ -11,7 +11,7 @@ use Drupal\Core\Cache\CacheCollector; use Drupal\Core\Database\Connection; use Drupal\Core\DestructableInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Utility\CacheArray; @@ -23,7 +23,7 @@ class AliasWhitelist extends CacheCollector { /** * The Key/Value Store to use for state. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -43,12 +43,12 @@ class AliasWhitelist extends CacheCollector { * The cache backend. * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock backend. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state keyvalue store. * @param \Drupal\Core\Database\Connection $connection * The database connection. */ - public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, KeyValueStoreInterface $state, Connection $connection) { + public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, StateInterface $state, Connection $connection) { parent::__construct($cid, $cache, $lock); $this->state = $state; $this->connection = $connection; diff --git a/core/lib/Drupal/Core/PrivateKey.php b/core/lib/Drupal/Core/PrivateKey.php index fd8bb55..762a664 100644 --- a/core/lib/Drupal/Core/PrivateKey.php +++ b/core/lib/Drupal/Core/PrivateKey.php @@ -7,7 +7,7 @@ namespace Drupal\Core; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Component\Utility\Crypt; /** @@ -18,17 +18,17 @@ class PrivateKey { /** * The state service. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; /** * Constructs the token generator. * - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state service. */ - function __construct(KeyValueStoreInterface $state) { + function __construct(StateInterface $state) { $this->state = $state; } diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php index 5d8fa9c..d88e6b1 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php @@ -16,7 +16,7 @@ use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Extension\ModuleHandler; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** * Controller class for field instances. @@ -45,7 +45,7 @@ class FieldInstanceStorageController extends ConfigStorageController { /** * The state keyvalue collection. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -68,10 +68,10 @@ class FieldInstanceStorageController extends ConfigStorageController { * The entity manager. * @param \Drupal\Core\Extension\ModuleHandler $module_handler * The module handler. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, KeyValueStoreInterface $state) { + public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, StateInterface $state) { parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory, $uuid_service); $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; diff --git a/core/modules/field/lib/Drupal/field/FieldStorageController.php b/core/modules/field/lib/Drupal/field/FieldStorageController.php index 24db2c2..0da91aa 100644 --- a/core/modules/field/lib/Drupal/field/FieldStorageController.php +++ b/core/modules/field/lib/Drupal/field/FieldStorageController.php @@ -16,7 +16,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Extension\ModuleHandler; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; /** * Controller class for fields. @@ -40,7 +40,7 @@ class FieldStorageController extends ConfigStorageController { /** * The state keyvalue collection. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -63,10 +63,10 @@ class FieldStorageController extends ConfigStorageController { * The entity manager. * @param \Drupal\Core\Extension\ModuleHandler $module_handler * The module handler. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, KeyValueStoreInterface $state) { + public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory, StorageInterface $config_storage, QueryFactory $entity_query_factory, UuidInterface $uuid_service, EntityManagerInterface $entity_manager, ModuleHandler $module_handler, StateInterface $state) { parent::__construct($entity_type, $entity_info, $config_factory, $config_storage, $entity_query_factory, $uuid_service); $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; diff --git a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php index 96305bd..b6fb820 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileManagedTestBase.php @@ -38,6 +38,8 @@ function setUp() { * 'insert', etc. */ function assertFileHooksCalled($expected) { + \Drupal::state()->resetCache(); + // Determine which hooks were called. $actual = array_keys(array_filter(file_test_get_all_calls())); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php index ba50def..4123fc0 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageFallbackTest.php @@ -26,7 +26,7 @@ public static function getInfo() { /** * The state storage service. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php index c33da33..ea4c9ce 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php @@ -11,7 +11,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; use Drupal\locale\StringStorageInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -31,7 +31,7 @@ /** * The state store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -54,12 +54,12 @@ * * @param \Drupal\locale\StringStorageInterface $locale_storage * The locale storage. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state service. * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager. */ - public function __construct(StringStorageInterface $locale_storage, KeyValueStoreInterface $state, LanguageManager $language_manager) { + public function __construct(StringStorageInterface $locale_storage, StateInterface $state, LanguageManager $language_manager) { $this->localeStorage = $locale_storage; $this->state = $state; $this->languageManager = $language_manager; diff --git a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php index 0dbd1ac..da32b99 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Search/NodeSearch.php @@ -14,7 +14,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Language\Language; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Session\AccountInterface; @@ -68,7 +68,7 @@ class NodeSearch extends SearchPluginBase implements AccessibleInterface, Search /** * The Drupal state object used to set 'node.cron_last'. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -111,7 +111,7 @@ static public function create(ContainerInterface $container, array $configuratio $container->get('plugin.manager.entity'), $container->get('module_handler'), $container->get('config.factory')->get('search.settings'), - $container->get('keyvalue')->get('state'), + $container->get('state'), $container->get('current_user') ); } @@ -133,12 +133,12 @@ static public function create(ContainerInterface $container, array $configuratio * A module manager object. * @param \Drupal\Core\Config\Config $search_settings * A config object for 'search.settings'. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The Drupal state object used to set 'node.cron_last'. * @param \Drupal\Core\Session\AccountInterface $account * The $account object to use for checking for access to advanced search. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, KeyValueStoreInterface $state, AccountInterface $account = NULL) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, StateInterface $state, AccountInterface $account = NULL) { $this->database = $database; $this->entityManager = $entity_manager; $this->moduleHandler = $module_handler; diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php index 19bc077..cef8953 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/views/display/RestExport.php @@ -8,7 +8,7 @@ namespace Drupal\rest\Plugin\views\display; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\views\Annotation\ViewsDisplay; use Drupal\Core\Annotation\Translation; @@ -99,14 +99,14 @@ class RestExport extends PathPluginBase { * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. * @param \Drupal\Core\ContentNegotiation $content_negotiation * The content negotiation library. * @param \Symfony\Component\HttpFoundation\Request $request * The request object. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteProviderInterface $route_provider, KeyValueStoreInterface $state, ContentNegotiation $content_negotiation, Request $request) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, ContentNegotiation $content_negotiation, Request $request) { parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state); $this->contentNegotiation = $content_negotiation; $this->request = $request; diff --git a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php index ae4bb43..05c6d5d 100644 --- a/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php +++ b/core/modules/rest/tests/Drupal/rest/Tests/CollectRoutesTest.php @@ -82,7 +82,7 @@ protected function setUp() { ->getMock(); $container->set('router.route_provider', $route_provider); - $state = $this->getMock('\Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $state = $this->getMock('\Drupal\Core\KeyValueStore\StateInterface'); $container->set('state', $state); $style_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager') diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php index 0ceef4b..7fc189a 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\search\SearchPluginManager; use Drupal\Core\Form\ConfigFormBase; @@ -44,7 +44,7 @@ class SearchSettingsForm extends ConfigFormBase { /** * The Drupal state storage service. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -59,10 +59,10 @@ class SearchSettingsForm extends ConfigFormBase { * The manager for search plugins. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key/value store interface, gives access to state based config settings. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, SearchPluginManager $manager, ModuleHandlerInterface $module_handler, KeyValueStoreInterface $state) { + public function __construct(ConfigFactory $config_factory, ContextInterface $context, SearchPluginManager $manager, ModuleHandlerInterface $module_handler, StateInterface $state) { parent::__construct($config_factory, $context); $this->searchSettings = $config_factory->get('search.settings'); $this->searchPluginManager = $manager; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 5eb5b26..dee1760 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -175,10 +175,8 @@ public function containerBuild(ContainerBuilder $container) { ->addArgument(new Reference('service_container')) ->addArgument(new Reference('settings')); - $container->register('state', 'Drupal\Core\KeyValueStore\KeyValueStoreInterface') - ->setFactoryService(new Reference('keyvalue')) - ->setFactoryMethod('get') - ->addArgument('state'); + $container->register('state', 'Drupal\Core\KeyValueStore\State') + ->addArgument(new Reference('keyvalue')); } if ($container->hasDefinition('path_processor_alias')) { diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 284df1d..b7659bd 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -1008,6 +1008,7 @@ protected function refreshVariables() { // Clear the tag cache. drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache'); \Drupal::service('config.factory')->reset(); + \Drupal::state()->resetCache(); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/CronForm.php b/core/modules/system/lib/Drupal/system/Form/CronForm.php index 84dddb1..5d94762 100644 --- a/core/modules/system/lib/Drupal/system/Form/CronForm.php +++ b/core/modules/system/lib/Drupal/system/Form/CronForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\ContextInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -22,7 +22,7 @@ class CronForm extends ConfigFormBase { /** * Stores the state storage service. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -33,10 +33,10 @@ class CronForm extends ConfigFormBase { * The factory for configuration objects. * @param \Drupal\Core\Config\Context\ContextInterface $context * The configuration context used for this configuration object. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueStoreInterface $state) { + public function __construct(ConfigFactory $config_factory, ContextInterface $context, StateInterface $state) { parent::__construct($config_factory, $context); $this->state = $state; } diff --git a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php index fa10960..693dc28 100644 --- a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php +++ b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\ContextInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -21,7 +21,7 @@ class SiteMaintenanceModeForm extends ConfigFormBase { /** * The state keyvalue collection. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -32,10 +32,10 @@ class SiteMaintenanceModeForm extends ConfigFormBase { * The factory for configuration objects. * @param \Drupal\Core\Config\Context\ContextInterface $context * The configuration context to use. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state keyvalue collection to use. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueStoreInterface $state) { + public function __construct(ConfigFactory $config_factory, ContextInterface $context, StateInterface $state) { parent::__construct($config_factory, $context); $this->state = $state; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php index 3391a14..ccf6070 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php @@ -32,7 +32,7 @@ /** * The state service. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; diff --git a/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php index 1c8ea06..9078493 100644 --- a/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php +++ b/core/modules/system/tests/modules/service_provider_test/lib/Drupal/service_provider_test/TestClass.php @@ -7,7 +7,7 @@ namespace Drupal\service_provider_test; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\DestructableInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -18,17 +18,17 @@ class TestClass implements EventSubscriberInterface, DestructableInterface { /** * The state keyvalue collection. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; /** * Constructor. * - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(KeyValueStoreInterface $state) { + public function __construct(StateInterface $state) { $this->state = $state; } diff --git a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php index 26108b9..c8b0437 100644 --- a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\MapArray; use Drupal\Core\DestructableInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\views\Plugin\views\display\DisplayRouterInterface; use Drupal\views\ViewExecutable; @@ -44,7 +44,7 @@ class RouteSubscriber extends RouteSubscriberBase implements DestructableInterfa /** * The state key value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -60,10 +60,10 @@ class RouteSubscriber extends RouteSubscriberBase implements DestructableInterfa * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(EntityManagerInterface $entity_manager, KeyValueStoreInterface $state) { + public function __construct(EntityManagerInterface $entity_manager, StateInterface $state) { $this->viewStorageController = $entity_manager->getStorageController('view'); $this->state = $state; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php index 19893c7..25a1fed 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/PathPluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\views\Plugin\views\display; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\KeyValueStore\StateInterface; use Drupal\Core\Routing\RouteCompiler; use Drupal\Core\Routing\RouteProviderInterface; use Drupal\views\Views; @@ -35,7 +35,7 @@ /** * The state key value store. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Drupal\Core\KeyValueStore\StateInterface */ protected $state; @@ -50,10 +50,10 @@ * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider. - * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\KeyValueStore\StateInterface $state * The state key value store. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteProviderInterface $route_provider, KeyValueStoreInterface $state) { + public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->routeProvider = $route_provider; diff --git a/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php b/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php index 8a69bd3..6e4c644 100644 --- a/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php @@ -44,7 +44,7 @@ class RouteSubscriberTest extends UnitTestCase { /** * The mocked key value storage. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\KeyValueStore\StateInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $state; @@ -68,7 +68,7 @@ protected function setUp() { ->method('getStorageController') ->with('view') ->will($this->returnValue($this->viewStorageController)); - $this->state = $this->getMock('\Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $this->state = $this->getMock('\Drupal\Core\KeyValueStore\StateInterface'); $this->routeSubscriber = new TestRouteSubscriber($this->entityManager, $this->state); } diff --git a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php index 8b87a45..0f5289f 100644 --- a/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/Plugin/display/PathPluginBaseTest.php @@ -43,7 +43,7 @@ class PathPluginBaseTest extends UnitTestCase { /** * The mocked key value storage. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\KeyValueStore\StateInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $state; @@ -62,7 +62,7 @@ protected function setUp() { parent::setUp(); $this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); - $this->state = $this->getMock('\Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $this->state = $this->getMock('\Drupal\Core\KeyValueStore\StateInterface'); $this->pathPlugin = $this->getMockBuilder('Drupal\views\Plugin\views\display\PathPluginBase') ->setConstructorArgs(array(array(), 'path_base', array(), $this->routeProvider, $this->state)) ->setMethods(NULL) diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php index b30bb34..12a0984 100644 --- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php @@ -77,7 +77,7 @@ public function testBuildRowEntityList() { array(array(), 'default', $display_manager->getDefinition('default')) ); $route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface'); - $state = $this->getMock('\Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $state = $this->getMock('\Drupal\Core\KeyValueStore\StateInterface'); $page_display = $this->getMock('Drupal\views\Plugin\views\display\Page', array('initDisplay', 'getPath'), array(array(), 'default', $display_manager->getDefinition('page'), $route_provider, $state) diff --git a/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php index bfbe65c..fecb135 100644 --- a/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/CssCollectionRendererUnitTest.php @@ -66,7 +66,7 @@ class CssCollectionRendererUnitTest extends UnitTestCase { /** * The state mock class. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\KeyValueStore\StateInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $state; @@ -81,7 +81,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->state = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $this->state = $this->getMock('Drupal\Core\KeyValueStore\StateInterface'); $this->renderer = new CssCollectionRenderer($this->state); $this->file_css_group = array( diff --git a/core/tests/Drupal/Tests/Core/PrivateKeyTest.php b/core/tests/Drupal/Tests/Core/PrivateKeyTest.php index a77a939..9f864f8 100644 --- a/core/tests/Drupal/Tests/Core/PrivateKeyTest.php +++ b/core/tests/Drupal/Tests/Core/PrivateKeyTest.php @@ -19,7 +19,7 @@ class PrivateKeyTest extends UnitTestCase { /** * The state mock class. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\KeyValueStore\StateInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $state; @@ -52,7 +52,7 @@ public function setUp() { parent::setUp(); $this->key = Crypt::randomStringHashed(55); - $this->state = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface'); + $this->state = $this->getMock('Drupal\Core\KeyValueStore\StateInterface'); $this->privateKey = new PrivateKey($this->state); }