ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Authentication\KeyValueStorage\SessionRepository Class Reference

Keeps key-value storage in the ILIAS session. More...

+ Inheritance diagram for ILIAS\Authentication\KeyValueStorage\SessionRepository:
+ Collaboration diagram for ILIAS\Authentication\KeyValueStorage\SessionRepository:

Public Member Functions

 has (StorageNamespace $namespace, string $key)
 
 read (StorageNamespace $namespace, string $key)
 
 readAll (StorageNamespace $namespace)
 Every present entry of one namespace. More...
 
 write (StorageNamespace $namespace, string $key, string $value)
 
 remove (StorageNamespace $namespace, string $key)
 
 removeAll (StorageNamespace $namespace)
 
 has (StorageNamespace $namespace, string $key)
 
 read (StorageNamespace $namespace, string $key)
 
 readAll (StorageNamespace $namespace)
 Every present entry of one namespace. More...
 
 write (StorageNamespace $namespace, string $key, string $value)
 
 remove (StorageNamespace $namespace, string $key)
 
 removeAll (StorageNamespace $namespace)
 

Private Member Functions

 sessionKey (StorageNamespace $namespace, string $key)
 
 namespacePrefix (StorageNamespace $namespace)
 

Private Attributes

const string PREFIX = 'kvs:'
 
const string SEPARATOR = ':'
 

Detailed Description

Keeps key-value storage in the ILIAS session.

Every entry is a session variable of its own, named "<prefix><namespace>:<key>". ilSession only knows single keys - it can neither list nor clear by prefix - so one nested array per namespace would mean reading and writing the whole array on every single write. Flat keys keep a write to one entry, at the price of scanning the session when a whole namespace is read or dropped, which happens rarely.

The colon is what separates namespace from key: it cannot occur in a namespace, and keys must not contain it, so no pair of namespace and key can ever produce the session key of another pair.

Definition at line 40 of file SessionRepository.php.

Member Function Documentation

◆ has()

ILIAS\Authentication\KeyValueStorage\SessionRepository::has ( StorageNamespace  $namespace,
string  $key 
)

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 46 of file SessionRepository.php.

46 : bool
47 {
48 return \ilSession::has($this->sessionKey($namespace, $key));
49 }
sessionKey(StorageNamespace $namespace, string $key)
has(string $class_name)

References ILIAS\GlobalScreen\has(), and ILIAS\Authentication\KeyValueStorage\SessionRepository\sessionKey().

+ Here is the call graph for this function:

◆ namespacePrefix()

ILIAS\Authentication\KeyValueStorage\SessionRepository::namespacePrefix ( StorageNamespace  $namespace)
private

◆ read()

ILIAS\Authentication\KeyValueStorage\SessionRepository::read ( StorageNamespace  $namespace,
string  $key 
)
Returns
string|null null if the key is not present

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 51 of file SessionRepository.php.

51 : ?string
52 {
53 $value = \ilSession::get($this->sessionKey($namespace, $key));
54
55 return \is_string($value) ? $value : null;
56 }
static get(string $a_var)

References ilSession\get(), and ILIAS\Authentication\KeyValueStorage\SessionRepository\sessionKey().

+ Here is the call graph for this function:

◆ readAll()

ILIAS\Authentication\KeyValueStorage\SessionRepository::readAll ( StorageNamespace  $namespace)

Every present entry of one namespace.

Returns
array<string, string> key => stored string; empty if the namespace holds nothing

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 58 of file SessionRepository.php.

58 : array
59 {
60 $prefix = $this->namespacePrefix($namespace);
61 $prefix_length = \strlen($prefix);
62 $entries = [];
63
64 foreach (\ilSession::keys() as $session_key) {
65 if (!\str_starts_with($session_key, $prefix)) {
66 continue;
67 }
68
69 $value = \ilSession::get($session_key);
70 if (!\is_string($value)) {
71 continue;
72 }
73
74 $entries[\substr($session_key, $prefix_length)] = $value;
75 }
76
77 return $entries;
78 }
static keys()
The names of all variables currently held in the session.

References ilSession\get(), ilSession\keys(), and ILIAS\Authentication\KeyValueStorage\SessionRepository\namespacePrefix().

+ Here is the call graph for this function:

◆ remove()

ILIAS\Authentication\KeyValueStorage\SessionRepository::remove ( StorageNamespace  $namespace,
string  $key 
)

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 85 of file SessionRepository.php.

85 : void
86 {
87 \ilSession::clear($this->sessionKey($namespace, $key));
88 }
static clear(string $a_var)

References ilSession\clear(), and ILIAS\Authentication\KeyValueStorage\SessionRepository\sessionKey().

+ Here is the call graph for this function:

◆ removeAll()

ILIAS\Authentication\KeyValueStorage\SessionRepository::removeAll ( StorageNamespace  $namespace)

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 90 of file SessionRepository.php.

90 : void
91 {
92 $prefix = $this->namespacePrefix($namespace);
93
94 foreach (\ilSession::keys() as $session_key) {
95 if (\str_starts_with($session_key, $prefix)) {
96 \ilSession::clear($session_key);
97 }
98 }
99 }

References ilSession\clear(), ilSession\keys(), and ILIAS\Authentication\KeyValueStorage\SessionRepository\namespacePrefix().

+ Here is the call graph for this function:

◆ sessionKey()

ILIAS\Authentication\KeyValueStorage\SessionRepository::sessionKey ( StorageNamespace  $namespace,
string  $key 
)
private

◆ write()

ILIAS\Authentication\KeyValueStorage\SessionRepository::write ( StorageNamespace  $namespace,
string  $key,
string  $value 
)

Implements ILIAS\KeyValueStorage\Repository.

Definition at line 80 of file SessionRepository.php.

80 : void
81 {
82 \ilSession::set($this->sessionKey($namespace, $key), $value);
83 }
static set(string $a_var, $a_val)
Set a value.

References ILIAS\Authentication\KeyValueStorage\SessionRepository\sessionKey(), and ilSession\set().

+ Here is the call graph for this function:

Field Documentation

◆ PREFIX

const string ILIAS\Authentication\KeyValueStorage\SessionRepository::PREFIX = 'kvs:'
private

Definition at line 42 of file SessionRepository.php.

◆ SEPARATOR

const string ILIAS\Authentication\KeyValueStorage\SessionRepository::SEPARATOR = ':'
private

The documentation for this class was generated from the following file: