class KeyValueFactory in MongoDB 8.2
Class KeyValueFactory builds KeyValue stores as MongoDB collections.
Hierarchy
- class \Drupal\mongodb_storage\KeyValueFactory implements KeyValueFactoryInterface
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_storageView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyValueFactory:: |
protected | property | The database in which the stores are created. | |
KeyValueFactory:: |
protected | property | A static cache for the stores. | |
KeyValueFactory:: |
constant | 1 | ||
KeyValueFactory:: |
constant | |||
KeyValueFactory:: |
public | function |
Constructs a new key/value store for a given collection name. Overrides KeyValueFactoryInterface:: |
1 |
KeyValueFactory:: |
public | function | KeyValueFactory constructor. | 1 |