ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Collection.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
21 
22 use LogicException;
23 
29 {
30  private array $values = [];
31 
35  public function getData(): array
36  {
37  return $this->values;
38  }
39 
44  public function add(string $key, $value): void
45  {
46  if ($this->exists($key)) {
47  throw new LogicException("Key $key already exists.");
48  }
49  $this->values[$key] = $value;
50  }
51 
56  public function get(string $key)
57  {
58  return $this->values[$key];
59  }
60 
66  public function is(string $key, $expected_value): bool
67  {
68  return ($this->exists($key) && $this->get($key) === $expected_value);
69  }
70 
75  public function exists(string $key): bool
76  {
77  return isset($this->values[$key]);
78  }
79 
84  public function replace(string $key, $value): void
85  {
86  if (!$this->exists($key)) {
87  throw new LogicException("Key $key does not exists.");
88  }
89  $this->values[$key] = $value;
90  }
91 }
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Collection.php:20