KeyValueFactory.php in MongoDB 8.2
File
modules/mongodb_storage/src/KeyValueFactory.php
View source
<?php
declare (strict_types=1);
namespace Drupal\mongodb_storage;
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
use Drupal\mongodb\DatabaseFactory;
class KeyValueFactory implements KeyValueFactoryInterface {
const DB_KEYVALUE = 'keyvalue';
const COLLECTION_PREFIX = 'kvp_';
protected $database;
protected $stores = [];
public function __construct(DatabaseFactory $databaseFactory) {
$this->database = $databaseFactory
->get(static::DB_KEYVALUE);
}
public function get($collection) {
$storeCollection = $this->database
->selectCollection(static::COLLECTION_PREFIX . $collection);
$store = new KeyValueStore($collection, $storeCollection);
return $store;
}
}
Classes
Name |
Description |
KeyValueFactory |
Class KeyValueFactory builds KeyValue stores as MongoDB collections. |