You are here

public function SessionBasedTempStoreFactory::get in Session Based Temporary Storage 8

Creates a PrivateTempStore.

Parameters

string $collection: The collection name to use for this key/value store. This is typically a shared namespace or module name, e.g. 'views', 'entity', etc.

null|int $expire: The time to live for items in the collection, in seconds.

string $path: The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. By default the value is to '/'.

Return value

\Drupal\session_based_temp_store\SessionBasedTempStore An instance of the key/value store.

File

src/SessionBasedTempStoreFactory.php, line 109

Class

SessionBasedTempStoreFactory
Creates a SessionBasedTempStore object for a given collection.

Namespace

Drupal\session_based_temp_store

Code

public function get($collection, $expire = NULL, $path = '/') {

  // Allow expire to be set per collection, use default if not provided.
  $expire = $expire ?? $this->expire;

  // Store the data for this collection in the database.
  $storage = $this->storageFactory
    ->get("user.private_tempstore.{$collection}");
  return new SessionBasedTempStore($storage, $this->lockBackend, $this->requestStack, $this->sessionConfiguration, $this->cookieName, $expire, $path);
}