You are here

class KeyValueFactory in MongoDB 8.2

Class KeyValueFactory builds KeyValue stores as MongoDB collections.

Hierarchy

Expanded class hierarchy of KeyValueFactory

3 files declare their use of KeyValueFactory
KeyValueTestBase.php in modules/mongodb_storage/tests/src/Kernel/KeyValueTestBase.php
SqlImport.php in modules/mongodb_storage/src/Install/SqlImport.php
SqlImportTest.php in modules/mongodb_storage/tests/src/Kernel/SqlImportTest.php
1 string reference to 'KeyValueFactory'
mongodb_storage.services.yml in modules/mongodb_storage/mongodb_storage.services.yml
modules/mongodb_storage/mongodb_storage.services.yml
1 service uses KeyValueFactory
keyvalue.mongodb in modules/mongodb_storage/mongodb_storage.services.yml
Drupal\mongodb_storage\KeyValueFactory

File

modules/mongodb_storage/src/KeyValueFactory.php, line 13

Namespace

Drupal\mongodb_storage
View source
class KeyValueFactory implements KeyValueFactoryInterface {
  const DB_KEYVALUE = 'keyvalue';
  const COLLECTION_PREFIX = 'kvp_';

  /**
   * The database in which the stores are created.
   *
   * @var \MongoDB\Database
   */
  protected $database;

  /**
   * A static cache for the stores.
   *
   * @var \Drupal\mongodb_storage\KeyValueStore[]
   */
  protected $stores = [];

  /**
   * KeyValueFactory constructor.
   *
   * @param \Drupal\mongodb\DatabaseFactory $databaseFactory
   *   The mongodb.database_factory service.
   */
  public function __construct(DatabaseFactory $databaseFactory) {
    $this->database = $databaseFactory
      ->get(static::DB_KEYVALUE);
  }

  /**
   * Constructs a new key/value store for a given collection name.
   *
   * @param string $collection
   *   The name of the collection holding key and value pairs.
   *
   * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   *   A key/value store implementation for the given $collection.
   */
  public function get($collection) {
    $storeCollection = $this->database
      ->selectCollection(static::COLLECTION_PREFIX . $collection);
    $store = new KeyValueStore($collection, $storeCollection);
    return $store;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyValueFactory::$database protected property The database in which the stores are created.
KeyValueFactory::$stores protected property A static cache for the stores.
KeyValueFactory::COLLECTION_PREFIX constant 1
KeyValueFactory::DB_KEYVALUE constant
KeyValueFactory::get public function Constructs a new key/value store for a given collection name. Overrides KeyValueFactoryInterface::get 1
KeyValueFactory::__construct public function KeyValueFactory constructor. 1