Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 12 |
| KeyValueDatabaseExpirableFactory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 12 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| get | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 5 |
|||
| garbageCollection | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory. | |
| */ | |
| namespace Drupal\Core\KeyValueStore; | |
| use Drupal\Component\Serialization\SerializationInterface; | |
| use Drupal\Core\Database\Connection; | |
| /** | |
| * Defines the key/value store factory for the database backend. | |
| */ | |
| class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterface { | |
| /** | |
| * Holds references to each instantiation so they can be terminated. | |
| * | |
| * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[] | |
| */ | |
| protected $storages = array(); | |
| /** | |
| * The serialization class to use. | |
| * | |
| * @var \Drupal\Component\Serialization\SerializationInterface | |
| */ | |
| protected $serializer; | |
| /** | |
| * The database connection. | |
| * | |
| * @var \Drupal\Core\Database\Connection | |
| */ | |
| protected $connection; | |
| /** | |
| * Constructs this factory object. | |
| * | |
| * @param \Drupal\Component\Serialization\SerializationInterface $serializer | |
| * The serialization class to use. | |
| * @param \Drupal\Core\Database\Connection $connection | |
| * The Connection object containing the key-value tables. | |
| */ | |
| function __construct(SerializationInterface $serializer, Connection $connection) { | |
| $this->serializer = $serializer; | |
| $this->connection = $connection; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function get($collection) { | |
| if (!isset($this->storages[$collection])) { | |
| $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection); | |
| } | |
| return $this->storages[$collection]; | |
| } | |
| /** | |
| * Deletes expired items. | |
| */ | |
| public function garbageCollection() { | |
| $this->connection->delete('key_value_expire') | |
| ->condition('expire', REQUEST_TIME, '<') | |
| ->execute(); | |
| } | |
| } |