class KeyValueFactory

Defines the key/value store factory.

Hierarchy

Expanded class hierarchy of KeyValueFactory

2 files declare their use of KeyValueFactory
AliasWhitelist.php in drupal/core/lib/Drupal/Core/Path/AliasWhitelist.php
Contains \Drupal\Core\Path\AliasWhitelist.
CronForm.php in drupal/core/modules/system/lib/Drupal/system/Form/CronForm.php
Contains \Drupal\system\Form\CronForm.
1 string reference to 'KeyValueFactory'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses KeyValueFactory

File

drupal/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php, line 14
Contains Drupal\Core\KeyValueStore\KeyValueFactory.

Namespace

Drupal\Core\KeyValueStore
View source
class KeyValueFactory {

  /**
   * Instantiated stores, keyed by collection name.
   *
   * @var array
   */
  protected $stores = array();

  /**
   * var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   */
  function __construct(ContainerInterface $container) {
    $this->container = $container;
  }

  /**
   * 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) {
    global $conf;
    if (!isset($this->stores[$collection])) {
      if (isset($conf['keyvalue_service_' . $collection])) {
        $service_name = $conf['keyvalue_service_' . $collection];
      }
      elseif (isset($conf['keyvalue_default'])) {
        $service_name = $conf['keyvalue_default'];
      }
      else {
        $service_name = 'keyvalue.database';
      }
      $this->stores[$collection] = $this->container
        ->get($service_name)
        ->get($collection);
    }
    return $this->stores[$collection];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyValueFactory::$container protected property var \Symfony\Component\DependencyInjection\ContainerInterface
KeyValueFactory::$stores protected property Instantiated stores, keyed by collection name.
KeyValueFactory::get public function Constructs a new key/value store for a given collection name. 1
KeyValueFactory::__construct function