class KeyValueFactory in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php \Drupal\Core\KeyValueStore\KeyValueFactory
- 9 core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php \Drupal\Core\KeyValueStore\KeyValueFactory
Defines the key/value store factory.
Hierarchy
- class \Drupal\Core\KeyValueStore\KeyValueFactory implements \Drupal\Core\KeyValueStore\KeyValueFactoryInterface
Expanded class hierarchy of KeyValueFactory
3 files declare their use of KeyValueFactory
- DatabaseStorageExpirableTest.php in core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ DatabaseStorageExpirableTest.php - DatabaseStorageTest.php in core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ DatabaseStorageTest.php - MemoryStorageTest.php in core/
tests/ Drupal/ KernelTests/ Core/ KeyValueStore/ MemoryStorageTest.php
1 string reference to 'KeyValueFactory'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses KeyValueFactory
File
- core/
lib/ Drupal/ Core/ KeyValueStore/ KeyValueFactory.php, line 10
Namespace
Drupal\Core\KeyValueStoreView source
class KeyValueFactory implements KeyValueFactoryInterface {
/**
* The specific setting name prefix.
*
* The collection name will be prefixed with this constant and used as a
* setting name. The setting value will be the id of a service.
*/
const SPECIFIC_PREFIX = 'keyvalue_service_';
/**
* The default setting name.
*
* This is a setting name that will be used if the specific setting does not
* exist. The setting value will be the id of a service.
*/
const DEFAULT_SETTING = 'default';
/**
* The default service id.
*
* If the default setting does not exist, this is the default service id.
*/
const DEFAULT_SERVICE = 'keyvalue.database';
/**
* Instantiated stores, keyed by collection name.
*
* @var array
*/
protected $stores = [];
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Collection-specific storage override options.
*
* @var array
*/
protected $options;
/**
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The service container.
* @param array $options
* (optional) Collection-specific storage override options.
*/
public function __construct(ContainerInterface $container, array $options = []) {
$this->container = $container;
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function get($collection) {
if (!isset($this->stores[$collection])) {
if (isset($this->options[$collection])) {
$service_id = $this->options[$collection];
}
elseif (isset($this->options[static::DEFAULT_SETTING])) {
$service_id = $this->options[static::DEFAULT_SETTING];
}
else {
$service_id = static::DEFAULT_SERVICE;
}
$this->stores[$collection] = $this->container
->get($service_id)
->get($collection);
}
return $this->stores[$collection];
}
}