annotate 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
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\user;
Chris@0 4
Chris@0 5 use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
Chris@0 6 use Drupal\Core\Lock\LockBackendInterface;
Chris@0 7 use Drupal\Core\Session\AccountProxyInterface;
Chris@0 8 use Symfony\Component\HttpFoundation\RequestStack;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Creates a PrivateTempStore object for a given collection.
Chris@0 12 */
Chris@0 13 class PrivateTempStoreFactory {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * The storage factory creating the backend to store the data.
Chris@0 17 *
Chris@0 18 * @var \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface
Chris@0 19 */
Chris@0 20 protected $storageFactory;
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The lock object used for this data.
Chris@0 24 *
Chris@0 25 * @var \Drupal\Core\Lock\LockBackendInterface
Chris@0 26 */
Chris@0 27 protected $lockBackend;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * The current user.
Chris@0 31 *
Chris@0 32 * @var \Drupal\Core\Session\AccountProxyInterface
Chris@0 33 */
Chris@0 34 protected $currentUser;
Chris@0 35
Chris@0 36 /**
Chris@0 37 * The request stack.
Chris@0 38 *
Chris@0 39 * @var \Symfony\Component\HttpFoundation\RequestStack
Chris@0 40 */
Chris@0 41 protected $requestStack;
Chris@0 42
Chris@0 43 /**
Chris@0 44 * The time to live for items in seconds.
Chris@0 45 *
Chris@0 46 * @var int
Chris@0 47 */
Chris@0 48 protected $expire;
Chris@0 49
Chris@0 50 /**
Chris@0 51 * Constructs a Drupal\user\PrivateTempStoreFactory object.
Chris@0 52 *
Chris@0 53 * @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $storage_factory
Chris@0 54 * The key/value store factory.
Chris@0 55 * @param \Drupal\Core\Lock\LockBackendInterface $lock_backend
Chris@0 56 * The lock object used for this data.
Chris@0 57 * @param \Drupal\Core\Session\AccountProxyInterface $current_user
Chris@0 58 * The current account.
Chris@0 59 * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
Chris@0 60 * The request stack.
Chris@0 61 * @param int $expire
Chris@0 62 * The time to live for items, in seconds.
Chris@0 63 */
Chris@0 64 public function __construct(KeyValueExpirableFactoryInterface $storage_factory, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire = 604800) {
Chris@0 65 $this->storageFactory = $storage_factory;
Chris@0 66 $this->lockBackend = $lock_backend;
Chris@0 67 $this->currentUser = $current_user;
Chris@0 68 $this->requestStack = $request_stack;
Chris@0 69 $this->expire = $expire;
Chris@0 70 }
Chris@0 71
Chris@0 72 /**
Chris@0 73 * Creates a PrivateTempStore.
Chris@0 74 *
Chris@0 75 * @param string $collection
Chris@0 76 * The collection name to use for this key/value store. This is typically
Chris@0 77 * a shared namespace or module name, e.g. 'views', 'entity', etc.
Chris@0 78 *
Chris@0 79 * @return \Drupal\user\PrivateTempStore
Chris@0 80 * An instance of the key/value store.
Chris@0 81 */
Chris@0 82 public function get($collection) {
Chris@0 83 // Store the data for this collection in the database.
Chris@0 84 $storage = $this->storageFactory->get("user.private_tempstore.$collection");
Chris@0 85 return new PrivateTempStore($storage, $this->lockBackend, $this->currentUser, $this->requestStack, $this->expire);
Chris@0 86 }
Chris@0 87
Chris@0 88 }