ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
Collection.php
Go to the documentation of this file.
2
3use LogicException;
4
11{
12
16 private $values = [];
17
18
22 public function getData() : array
23 {
24 return $this->values;
25 }
26
27
32 public function add(string $key, $value)
33 {
34 if ($this->exists($key)) {
35 throw new LogicException("Key {$key} already exists.");
36 }
37 $this->values[$key] = $value;
38 }
39
40
46 public function get(string $key)
47 {
48 return $this->values[$key];
49 }
50
51
58 public function is(string $key, $expected_value) : bool
59 {
60 return ($this->exists($key) && $this->get($key) === $expected_value);
61 }
62
63
69 public function exists(string $key) : bool
70 {
71 return isset($this->values[$key]);
72 }
73
74
79 public function replace(string $key, $value)
80 {
81 if (!$this->exists($key)) {
82 throw new LogicException("Key {$key} does not exists.");
83 }
84 $this->values[$key] = $value;
85 }
86}
An exception for terminatinating execution or to throw for unit testing.