class SessionBasedTempStoreFactory in Session Based Temporary Storage 8
Creates a SessionBasedTempStore object for a given collection.
Hierarchy
- class \Drupal\session_based_temp_store\SessionBasedTempStoreFactory
Expanded class hierarchy of SessionBasedTempStoreFactory
1 string reference to 'SessionBasedTempStoreFactory'
1 service uses SessionBasedTempStoreFactory
File
- src/
SessionBasedTempStoreFactory.php, line 13
Namespace
Drupal\session_based_temp_storeView source
class SessionBasedTempStoreFactory {
/**
* The storage factory creating the backend to store the data.
*
* @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface
*/
protected $storageFactory;
/**
* The lock object used for this data.
*
* @var \Drupal\Core\Lock\LockBackendInterface
*/
protected $lockBackend;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The session configuration.
*
* @var \Drupal\Core\Session\SessionConfigurationInterface
*/
protected $sessionConfiguration;
/**
* The time to live for items in seconds.
*
* @var int
*/
protected $expire;
/**
* The name of a cookie which will hold the storage ID.
*
* By default the value is to 'SESSbasedTempStoreId'.
*
* @var string
*/
protected $cookieName;
/**
* Constructs a SessionBasedTempStoreFactory object.
*
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
* The key/value store factory.
* @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
* The lock object used for this data.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
* The session configuration interface.
* @param int $expire
* The time to live for items, in seconds.
* @param string $cookie_name
* The name of a cookie which will hold the storage ID.
*/
public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, RequestStack $request_stack, SessionConfigurationInterface $session_configuration, $expire, $cookie_name) {
$this->storageFactory = $storage_factory;
$this->lockBackend = $lock_backend;
$this->requestStack = $request_stack;
$this->sessionConfiguration = $session_configuration;
$this->expire = $expire;
$this->cookieName = $cookie_name;
}
/**
* Creates a PrivateTempStore.
*
* @param 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.
* @param null|int $expire
* The time to live for items in the collection, in seconds.
* @param 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 \Drupal\session_based_temp_store\SessionBasedTempStore
* An instance of the key/value store.
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SessionBasedTempStoreFactory:: |
protected | property | The name of a cookie which will hold the storage ID. | |
SessionBasedTempStoreFactory:: |
protected | property | The time to live for items in seconds. | |
SessionBasedTempStoreFactory:: |
protected | property | The lock object used for this data. | |
SessionBasedTempStoreFactory:: |
protected | property | The request stack. | |
SessionBasedTempStoreFactory:: |
protected | property | The session configuration. | |
SessionBasedTempStoreFactory:: |
protected | property | The storage factory creating the backend to store the data. | |
SessionBasedTempStoreFactory:: |
public | function | Creates a PrivateTempStore. | |
SessionBasedTempStoreFactory:: |
public | function | Constructs a SessionBasedTempStoreFactory object. |