You are here

class EntityconnectCache in Entity connect 8.2

A custom class for managing the Entityconnect cache.

@package Drupal\entityconnect

Hierarchy

Expanded class hierarchy of EntityconnectCache

1 file declares its use of EntityconnectCache
EntityconnectController.php in src/Controller/EntityconnectController.php
1 string reference to 'EntityconnectCache'
entityconnect.services.yml in ./entityconnect.services.yml
entityconnect.services.yml
1 service uses EntityconnectCache
entityconnect.cache in ./entityconnect.services.yml
Drupal\entityconnect\EntityconnectCache

File

src/EntityconnectCache.php, line 15

Namespace

Drupal\entityconnect
View 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

Namesort descending Modifiers Type Description Overrides
EntityconnectCache::$account private property The current user account.
EntityconnectCache::$sessionManager private property The session manager object.
EntityconnectCache::$store private property The private temporary storage.
EntityconnectCache::create public static function Uses Symfony's ContainerInterface to declare dependency for constructor.
EntityconnectCache::delete public function Deletes the key/data pair from our PrivateTempStore.
EntityconnectCache::get public function Gets the data from our PrivateTempStore for the given key.
EntityconnectCache::set public function Stores the key/data pair in our PrivateTempStore.
EntityconnectCache::__construct public function Saves our dependencies.