ILIAS  release_8 Revision v8.24
State.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5/* Copyright (c) 2018 - Richard Klees <richard.klees@concepts-and-training.de> - Extended GPL, see LICENSE */
6
7namespace ILIAS\KioskMode;
8
12class State
13{
17 protected ?array $store = null;
18
22 public function withValueFor(string $key, string $value): State
23 {
24 $clone = clone $this;
25 $clone->store[$key] = $value;
26 return $clone;
27 }
28
32 public function withoutKey(string $key): State
33 {
34 $clone = clone $this;
35 unset($clone->store[$key]);
36 return $clone;
37 }
38
42 public function getValueFor(string $key): ?string
43 {
44 if (!$this->store) {
45 return null;
46 }
47 return $this->store[$key];
48 }
49
53 public function serialize(): string
54 {
55 return json_encode($this->store, JSON_THROW_ON_ERROR);
56 }
57}
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:13
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:22
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:32
serialize()
Get the key-value store as string.
Definition: State.php:53
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:42
string $key
Consumer key/client ID value.
Definition: System.php:193