Mercurial > hg > isophonics-drupal-site
diff core/modules/user/src/PrivateTempStoreFactory.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/user/src/PrivateTempStoreFactory.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,88 @@ +<?php + +namespace Drupal\user; + +use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; +use Drupal\Core\Lock\LockBackendInterface; +use Drupal\Core\Session\AccountProxyInterface; +use Symfony\Component\HttpFoundation\RequestStack; + +/** + * Creates a PrivateTempStore object for a given collection. + */ +class PrivateTempStoreFactory { + + /** + * 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 current user. + * + * @var \Drupal\Core\Session\AccountProxyInterface + */ + protected $currentUser; + + /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** + * The time to live for items in seconds. + * + * @var int + */ + protected $expire; + + /** + * Constructs a Drupal\user\PrivateTempStoreFactory 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 \Drupal\Core\Session\AccountProxyInterface $current_user + * The current account. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. + * @param int $expire + * The time to live for items, in seconds. + */ + public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) { + $this->storageFactory = $storage_factory; + $this->lockBackend = $lock_backend; + $this->currentUser = $current_user; + $this->requestStack = $request_stack; + $this->expire = $expire; + } + + /** + * 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. + * + * @return \Drupal\user\PrivateTempStore + * An instance of the key/value store. + */ + public function get($collection) { + // Store the data for this collection in the database. + $storage = $this->storageFactory->get("user.private_tempstore.$collection"); + return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire); + } + +}