ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
State.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2018 - Richard Klees <richard.klees@concepts-and-training.de> - Extended GPL, see LICENSE */
3 
4 namespace ILIAS\KioskMode;
5 
9 class State
10 {
11 
15  protected $store;
16 
20  public function withValueFor(string $key, string $value) : State
21  {
22  $clone = clone $this;
23  $clone->store[$key] = $value;
24  return $clone;
25  }
26 
30  public function withoutKey(string $key) : State
31  {
32  $clone = clone $this;
33  unset($clone->store[$key]);
34  return $clone;
35  }
36 
40  public function getValueFor(string $key) : ?string
41  {
42  if (!$this->store) {
43  return null;
44  }
45  return $this->store[$key];
46  }
47 
51  public function serialize() : string
52  {
53  return json_encode($this->store);
54  }
55 }
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:20
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:40
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:9
serialize()
Get the key-value store as string.
Definition: State.php:51
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:30