You are here

public function PrivateTempStore::set in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/PrivateTempStore.php \Drupal\user\PrivateTempStore::set()

Stores a particular key/value pair in this PrivateTempStore.

Parameters

string $key: The key of the data to store.

mixed $value: The data to store.

File

core/modules/user/src/PrivateTempStore.php, line 119
Contains \Drupal\user\PrivateTempStore.

Class

PrivateTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\user

Code

public function set($key, $value) {
  $key = $this
    ->createkey($key);
  if (!$this->lockBackend
    ->acquire($key)) {
    $this->lockBackend
      ->wait($key);
    if (!$this->lockBackend
      ->acquire($key)) {
      throw new TempStoreException("Couldn't acquire lock to update item '{$key}' in '{$this->storage->getCollectionName()}' temporary storage.");
    }
  }
  $value = (object) array(
    'owner' => $this
      ->getOwner(),
    'data' => $value,
    'updated' => (int) $this->requestStack
      ->getMasterRequest()->server
      ->get('REQUEST_TIME'),
  );
  $this->storage
    ->setWithExpire($key, $value, $this->expire);
  $this->lockBackend
    ->release($key);
}