Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / KeyValueStore / KeyValueDatabaseExpirableFactory.php
1 <?php
2
3 namespace Drupal\Core\KeyValueStore;
4
5 use Drupal\Component\Serialization\SerializationInterface;
6 use Drupal\Core\Database\Connection;
7
8 /**
9  * Defines the key/value store factory for the database backend.
10  */
11 class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterface {
12
13   /**
14    * Holds references to each instantiation so they can be terminated.
15    *
16    * @var \Drupal\Core\KeyValueStore\DatabaseStorageExpirable[]
17    */
18   protected $storages = [];
19
20   /**
21    * The serialization class to use.
22    *
23    * @var \Drupal\Component\Serialization\SerializationInterface
24    */
25   protected $serializer;
26
27   /**
28    * The database connection.
29    *
30    * @var \Drupal\Core\Database\Connection
31    */
32   protected $connection;
33
34   /**
35    * Constructs this factory object.
36    *
37    * @param \Drupal\Component\Serialization\SerializationInterface $serializer
38    *   The serialization class to use.
39    * @param \Drupal\Core\Database\Connection $connection
40    *   The Connection object containing the key-value tables.
41    */
42   public function __construct(SerializationInterface $serializer, Connection $connection) {
43     $this->serializer = $serializer;
44     $this->connection = $connection;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function get($collection) {
51     if (!isset($this->storages[$collection])) {
52       $this->storages[$collection] = new DatabaseStorageExpirable($collection, $this->serializer, $this->connection);
53     }
54     return $this->storages[$collection];
55   }
56
57   /**
58    * Deletes expired items.
59    */
60   public function garbageCollection() {
61     $this->connection->delete('key_value_expire')
62       ->condition('expire', REQUEST_TIME, '<')
63       ->execute();
64   }
65
66 }