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