diff --git a/core/core.services.yml b/core/core.services.yml index c0411aa..395729b 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -124,9 +124,9 @@ services: arguments: ['@service_container', '@settings'] keyvalue.expirable.database: class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory + arguments: ['@serialization.phpserialize', '@database'] tags: - { name: needs_destruction } - arguments: ['@database'] serialization.phpserialize: class: Drupal\Core\Serialization\PhpSerialize diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php index 7861b0c..f4923cf 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php @@ -10,7 +10,7 @@ use Drupal\Core\DestructableInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\Merge; -use Drupal\Core\Serialization\PhpSerialize; +use Drupal\Core\Serialization\SerializationInterface; /** * Defines a default key/value store implementation for expiring items. @@ -38,16 +38,15 @@ class DatabaseStorageExpirable extends DatabaseStorage implements KeyValueStoreE * * @param string $collection * The name of the collection holding key and value pairs. - * @param array $options - * An associative array of options for the key/value storage collection. - * Keys used: - * - connection: (optional) The database connection to use for storing the - * data. Defaults to the current connection. - * - table: (optional) The name of the SQL table to use. Defaults to - * key_value_expire. + * @param \Drupal\Core\Serialization\SerializationInterface $serializer + * The serialization class to use. + * @param \Drupal\Core\Database\Connection $connection + * The database connection to use. + * @param string $table + * The name of the SQL table to use, defaults to key_value_expire. */ - public function __construct($collection, Connection $connection, $table = 'key_value_expire') { - parent::__construct($collection, new PhpSerialize(), $connection, $table); + public function __construct($collection, SerializationInterface $serializer, Connection $connection, $table = 'key_value_expire') { + parent::__construct($collection, $serializer, $connection, $table); } /** diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php index 9000e20..895d7ed 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php @@ -9,6 +9,7 @@ use Drupal\Core\DestructableInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\Serialization\SerializationInterface; /** * Defines the key/value store factory for the database backend. @@ -23,6 +24,13 @@ class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterf protected $storages = array(); /** + * The serialization class to use. + * + * @var \Drupal\Core\Serialization\SerializationInterface + */ + protected $serializer; + + /** * The database connection. * * @var \Drupal\Core\Database\Connection @@ -32,11 +40,13 @@ class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterf /** * Constructs this factory object. * - * + * @param \Drupal\Core\Serialization\SerializationInterface $serializer + * The serialization class to use. * @param \Drupal\Core\Database\Connection $connection * The Connection object containing the key-value tables. */ - function __construct(Connection $connection) { + function __construct(SerializationInterface $serializer, Connection $connection) { + $this->serializer = $serializer; $this->connection = $connection; } @@ -45,7 +55,7 @@ function __construct(Connection $connection) { */ public function get($collection) { if (!isset($this->storages[$collection])) { - $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->connection); + $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection); } return $this->storages[$collection]; } 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 5f7365d..d53b914 100644 --- a/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/KeyValueStore/DatabaseStorageExpirableTest.php @@ -35,7 +35,10 @@ protected function setUp() { ->addArgument('default'); $this->container ->register('keyvalue.expirable.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory') + ->addArgument(new Reference('serialization.phpserialize')) ->addArgument(new Reference('database')); + $this->container + ->register('serialization.phpserialize', 'Drupal\Core\Serialization\PhpSerialize'); $this->settingsSet('keyvalue_expirable_default', 'keyvalue.expirable.database'); }