KeyValueDatabaseFactory.php 1.14 KB
Newer Older
1 2 3
<?php

namespace Drupal\Core\KeyValueStore;
4 5

use Drupal\Component\Serialization\SerializationInterface;
6 7 8 9 10
use Drupal\Core\Database\Connection;

/**
 * Defines the key/value store factory for the database backend.
 */
11
class KeyValueDatabaseFactory implements KeyValueFactoryInterface {
12 13

  /**
14 15 16 17 18 19 20 21
   * The serialization class to use.
   *
   * @var \Drupal\Component\Serialization\SerializationInterface
   */
  protected $serializer;

  /**
   * The database connection to use.
22
   *
23 24 25 26 27 28
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;

  /**
   * Constructs this factory object.
29
   *
30 31
   * @param \Drupal\Component\Serialization\SerializationInterface $serializer
   *   The serialization class to use.
32 33 34
   * @param \Drupal\Core\Database\Connection $connection
   *   The Connection object containing the key-value tables.
   */
35
  public function __construct(SerializationInterface $serializer, Connection $connection) {
36
    $this->serializer = $serializer;
37 38 39 40
    $this->connection = $connection;
  }

  /**
41
   * {@inheritdoc}
42 43
   */
  public function get($collection) {
44
    return new DatabaseStorage($collection, $this->serializer, $this->connection);
45
  }
46

47
}