ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4namespace ILIAS\KioskMode;
5
9class 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}
An exception for terminatinating execution or to throw for unit testing.
Keeps the state of a view in a simple stringly type key-value store.
Definition: State.php:10
withValueFor(string $key, string $value)
Set a value for a key of the state.
Definition: State.php:20
withoutKey(string $key)
Remove the key-value-pair.
Definition: State.php:30
serialize()
Get the key-value store as string.
Definition: State.php:51
getValueFor(string $key)
Get the value for the given key.
Definition: State.php:40