ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
Collection.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
21 
22 use LogicException;
23 
29 {
33  private $values = [];
34 
38  public function getData() : array
39  {
40  return $this->values;
41  }
42 
47  public function add(string $key, $value) : void
48  {
49  if ($this->exists($key)) {
50  throw new LogicException("Key $key already exists.");
51  }
52  $this->values[$key] = $value;
53  }
54 
59  public function get(string $key)
60  {
61  return $this->values[$key];
62  }
63 
69  public function is(string $key, $expected_value) : bool
70  {
71  return ($this->exists($key) && $this->get($key) === $expected_value);
72  }
73 
78  public function exists(string $key) : bool
79  {
80  return isset($this->values[$key]);
81  }
82 
87  public function replace(string $key, $value) : void
88  {
89  if (!$this->exists($key)) {
90  throw new LogicException("Key $key does not exists.");
91  }
92  $this->values[$key] = $value;
93  }
94 }