class EntityconnectCache in Entity connect 8.2
A custom class for managing the Entityconnect cache.
@package Drupal\entityconnect
Hierarchy
- class \Drupal\entityconnect\EntityconnectCache
Expanded class hierarchy of EntityconnectCache
1 file declares its use of EntityconnectCache
- EntityconnectController.php in src/
Controller/ EntityconnectController.php
1 string reference to 'EntityconnectCache'
1 service uses EntityconnectCache
File
- src/
EntityconnectCache.php, line 15
Namespace
Drupal\entityconnectView source
class EntityconnectCache {
/**
* The private temporary storage.
*
* @var \Drupal\Core\TempStore\PrivateTempStore
*/
private $store;
/**
* The session manager object.
*
* @var \Drupal\Core\Session\SessionManager
*/
private $sessionManager;
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountInterface
*/
private $account;
/**
* Saves our dependencies.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $store
* The private storage object.
* @param \Drupal\Core\Session\SessionManager $sessionManager
* The session manager.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user account object.
*/
public function __construct(PrivateTempStoreFactory $store, SessionManager $sessionManager, AccountInterface $account) {
$this->store = $store
->get('entityconnect');
$this->sessionManager = $sessionManager;
$this->account = $account;
// Start a manual session for anonymous users.
if ($account
->isAnonymous() && !isset($_SESSION['entityconnect_session'])) {
$_SESSION['entityconnect_session'] = TRUE;
$sessionManager
->start();
}
}
/**
* Uses Symfony's ContainerInterface to declare dependency for constructor.
*
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'), $container
->get('session_manager'), $container
->get('current_user'));
}
/**
* Gets the data from our PrivateTempStore for the given key.
*
* @param string $key
* The cache key.
*
* @return mixed
* The cache data.
*/
public function get($key) {
return $this->store
->get($key);
}
/**
* Stores the key/data pair in our PrivateTempStore.
*
* @param string $key
* The cache key.
* @param mixed $data
* The cache data.
*
* @throws \Drupal\Core\TempStore\TempStoreException
*/
public function set($key, $data) {
$this->store
->set($key, $data);
}
/**
* Deletes the key/data pair from our PrivateTempStore.
*
* @param string $key
* The cache key.
*
* @throws \Drupal\Core\TempStore\TempStoreException
*/
public function delete($key) {
$this->store
->delete($key);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityconnectCache:: |
private | property | The current user account. | |
EntityconnectCache:: |
private | property | The session manager object. | |
EntityconnectCache:: |
private | property | The private temporary storage. | |
EntityconnectCache:: |
public static | function | Uses Symfony's ContainerInterface to declare dependency for constructor. | |
EntityconnectCache:: |
public | function | Deletes the key/data pair from our PrivateTempStore. | |
EntityconnectCache:: |
public | function | Gets the data from our PrivateTempStore for the given key. | |
EntityconnectCache:: |
public | function | Stores the key/data pair in our PrivateTempStore. | |
EntityconnectCache:: |
public | function | Saves our dependencies. |