ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
State.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\KioskMode;
22 
26 class State
27 {
31  protected ?array $store = null;
32 
36  public function withValueFor(string $key, string $value): State
37  {
38  $clone = clone $this;
39  $clone->store[$key] = $value;
40  return $clone;
41  }
42 
46  public function withoutKey(string $key): State
47  {
48  $clone = clone $this;
49  unset($clone->store[$key]);
50  return $clone;
51  }
52 
56  public function getValueFor(string $key): ?string
57  {
58  if (!$this->store) {
59  return null;
60  }
61  return $this->store[$key];
62  }
63 
67  public function serialize(): string
68  {
69  return json_encode($this->store, JSON_THROW_ON_ERROR);
70  }
71 }
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:36
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:56
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:26
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
serialize()
Get the key-value store as string.
Definition: State.php:67
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:46