KeyValueDatabaseFactory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Drupal\Core\KeyValueStore;
  3. use Drupal\Component\Serialization\SerializationInterface;
  4. use Drupal\Core\Database\Connection;
  5. /**
  6. * Defines the key/value store factory for the database backend.
  7. */
  8. class KeyValueDatabaseFactory implements KeyValueFactoryInterface {
  9. /**
  10. * The serialization class to use.
  11. *
  12. * @var \Drupal\Component\Serialization\SerializationInterface
  13. */
  14. protected $serializer;
  15. /**
  16. * The database connection to use.
  17. *
  18. * @var \Drupal\Core\Database\Connection
  19. */
  20. protected $connection;
  21. /**
  22. * Constructs this factory object.
  23. *
  24. * @param \Drupal\Component\Serialization\SerializationInterface $serializer
  25. * The serialization class to use.
  26. * @param \Drupal\Core\Database\Connection $connection
  27. * The Connection object containing the key-value tables.
  28. */
  29. public function __construct(SerializationInterface $serializer, Connection $connection) {
  30. $this->serializer = $serializer;
  31. $this->connection = $connection;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function get($collection) {
  37. return new DatabaseStorage($collection, $this->serializer, $this->connection);
  38. }
  39. }