You are here

public function SharedTempStore::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/TempStore/SharedTempStore.php \Drupal\Core\TempStore\SharedTempStore::__construct()

Constructs a new object for accessing data from a key/value store.

Parameters

\Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $storage: The key/value storage object used for this data. Each storage object represents a particular collection of data and will contain any number of key/value pairs.

\Drupal\Core\Lock\LockBackendInterface $lock_backend: The lock object used for this data.

mixed $owner: The owner key to store along with the data (e.g. a user or session ID).

\Symfony\Component\HttpFoundation\RequestStack $request_stack: The request stack.

\Drupal\Core\Session\AccountProxyInterface $current_user: The current user.

int $expire: The time to live for items, in seconds.

File

core/lib/Drupal/Core/TempStore/SharedTempStore.php, line 106

Class

SharedTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

public function __construct(KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, $owner, RequestStack $request_stack, $current_user = NULL, $expire = 604800) {
  $this->storage = $storage;
  $this->lockBackend = $lock_backend;
  $this->owner = $owner;
  $this->requestStack = $request_stack;
  if (!$current_user instanceof AccountProxyInterface) {
    @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.2.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED);
    if (is_int($current_user)) {

      // If the $current_user argument is numeric then this object has been
      // instantiated with the old constructor signature.
      $expire = $current_user;
    }
    $current_user = \Drupal::currentUser();
  }
  $this->currentUser = $current_user;
  $this->expire = $expire;
}