-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAccessProxy.php
More file actions
38 lines (32 loc) · 911 Bytes
/
ArrayAccessProxy.php
File metadata and controls
38 lines (32 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace MaxieSystems;
final readonly class ArrayAccessProxy implements \ArrayAccess
{
public function __construct(
private readonly object $subject,
private readonly bool $readonly = true
) {
}
public function offsetExists(mixed $offset): bool
{
return isset($this->subject->$offset);
}
public function offsetGet(mixed $offset): mixed
{
return $this->subject->$offset;
}
public function offsetSet(mixed $offset, mixed $value): void
{
if ($this->readonly) {
throw new \Error(EMessages::readonlyProperty($this, $offset));
}
$this->subject->$offset = $value;
}
public function offsetUnset(mixed $offset): void
{
if ($this->readonly) {
throw new \Error(EMessages::readonlyProperty($this, $offset));
}
unset($this->subject->$offset);
}
}