MCPcopy Create free account
hub / github.com/Rello/analytics / DataSession

Class DataSession

lib/DataSession.php:14–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12use OCP\ISession;
13
14class DataSession
15{
16 /** @var ISession */
17 protected $session;
18
19 public function __construct(ISession $session)
20 {
21 $this->session = $session;
22 }
23
24 public function getPasswordForShare(string $token): ?string
25 {
26 return $this->getValue('data-password', $token);
27 }
28
29 protected function getValue(string $key, string $token): ?string
30 {
31 $values = $this->getValues($key);
32 if (!isset($values[$token])) {
33 return null;
34 }
35 return $values[$token];
36 }
37
38 protected function getValues(string $key): array
39 {
40 $values = $this->session->get($key);
41 if ($values === null) {
42 return [];
43 }
44 $values = json_decode($values, true);
45 if ($values === null) {
46 return [];
47 }
48 return $values;
49 }
50
51 public function setPasswordForShare(string $token, string $password): void
52 {
53 $this->setValue('data-password', $token, $password);
54 }
55
56 protected function setValue(string $key, string $token, string $value): void
57 {
58 $values = $this->session->get($key);
59 if ($values === null) {
60 $values = [];
61 } else {
62 $values = json_decode($values, true);
63 if ($values === null) {
64 $values = [];
65 }
66 }
67 $values[$token] = $value;
68 $this->session->set($key, json_encode($values));
69 }
70
71 public function removePasswordForShare(string $token): void

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected