ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Collection.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use LogicException;
24
30{
31 private array $values = [];
32
36 public function getData(): array
37 {
38 return $this->values;
39 }
40
45 public function add(string $key, $value): void
46 {
47 if ($this->exists($key)) {
48 throw new LogicException("Key $key already exists.");
49 }
50 $this->values[$key] = $value;
51 }
52
57 public function get(string $key)
58 {
59 return $this->values[$key];
60 }
61
67 public function is(string $key, $expected_value): bool
68 {
69 return ($this->exists($key) && $this->get($key) === $expected_value);
70 }
71
76 public function exists(string $key): bool
77 {
78 return isset($this->values[$key]);
79 }
80
85 public function replace(string $key, $value): void
86 {
87 if (!$this->exists($key)) {
88 throw new LogicException("Key $key does not exists.");
89 }
90 $this->values[$key] = $value;
91 }
92}