ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
State.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\KioskMode;
22
26class 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}
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:27
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:36
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:46
serialize()
Get the key-value store as string.
Definition: State.php:67
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:56