ILIAS  release_8 Revision v8.24
EntryLockingStringMap.php
Go to the documentation of this file.
1<?php
2
4
7use ILIAS\FileUpload\ScalarTypeCheckAware;
8
9/******************************************************************************
10 *
11 * This file is part of ILIAS, a powerful learning management system.
12 *
13 * ILIAS is licensed with the GPL-3.0, you should have received a copy
14 * of said license along with the source code.
15 *
16 * If this is not the case or you just want to try ILIAS, you'll find
17 * us at:
18 * https://www.ilias.de
19 * https://github.com/ILIAS-eLearning
20 *
21 *****************************************************************************/
34final class EntryLockingStringMap implements StringMap
35{
36 use ScalarTypeCheckAware;
37 private \ArrayObject $map;
38
39
43 public function __construct()
44 {
45 $this->map = new \ArrayObject();
46 }
47
48
58 public function get(string $key): string
59 {
60 $this->stringTypeCheck($key, 'key');
61
62 if ($this->map->offsetExists($key)) {
63 return $this->map->offsetGet($key);
64 }
65
66 throw new NoSuchElementException("No meta data associated with key \"$key\".");
67 }
68
69
77 public function toArray(): array
78 {
79 return $this->map->getArrayCopy();
80 }
81
82
91 public function has(string $key): bool
92 {
93 $this->stringTypeCheck($key, 'key');
94
95 return $this->map->offsetExists($key);
96 }
97
98
111 public function put(string $key, string $value): void
112 {
113 $this->stringTypeCheck($key, 'key');
114 $this->stringTypeCheck($value, 'value');
115
116 if ($this->map->offsetExists($key)) {
117 throw new ElementAlreadyExistsException("Element $key can not be overwritten.");
118 }
119
120 $this->map->offsetSet($key, $value);
121 }
122}
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.
toArray()
Returns all currently known entries.
string $key
Consumer key/client ID value.
Definition: System.php:193