ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
EntryLockingStringMap.php
Go to the documentation of this file.
1 <?php
2 
20 
24 
37 final class EntryLockingStringMap implements StringMap
38 {
40  private \ArrayObject $map;
41 
42 
46  public function __construct()
47  {
48  $this->map = new \ArrayObject();
49  }
50 
51 
61  public function get(string $key): string
62  {
63  $this->stringTypeCheck($key, 'key');
64 
65  if ($this->map->offsetExists($key)) {
66  return $this->map->offsetGet($key);
67  }
68 
69  throw new NoSuchElementException("No meta data associated with key \"$key\".");
70  }
71 
72 
80  public function toArray(): array
81  {
82  return $this->map->getArrayCopy();
83  }
84 
85 
94  public function has(string $key): bool
95  {
96  $this->stringTypeCheck($key, 'key');
97 
98  return $this->map->offsetExists($key);
99  }
100 
101 
114  public function put(string $key, string $value): void
115  {
116  $this->stringTypeCheck($key, 'key');
117  $this->stringTypeCheck($value, 'value');
118 
119  if ($this->map->offsetExists($key)) {
120  throw new ElementAlreadyExistsException("Element $key can not be overwritten.");
121  }
122 
123  $this->map->offsetSet($key, $value);
124  }
125 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
has(string $key)
Probe if the key is known and associated with a value.
put(string $key, string $value)
Puts a new key value pair into the string array.