-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Context.php
61 lines (48 loc) · 1.32 KB
/
Context.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\Filesystem;
use ArrayIterator;
use SonsOfPHP\Component\Filesystem\Exception\FilesystemException;
use SonsOfPHP\Contract\Filesystem\ContextInterface;
use Traversable;
/**
* @author Joshua Estes <[email protected]>
*/
class Context implements ContextInterface
{
public function __construct(
private array $context = [],
) {}
public function offsetSet(mixed $offset, mixed $value): void
{
if (!is_string($offset)) {
throw new FilesystemException();
}
$this->context[$offset] = $value;
}
public function offsetExists(mixed $offset): bool
{
if (!is_string($offset)) {
throw new FilesystemException();
}
return array_key_exists($offset, $this->context);
}
public function offsetUnset(mixed $offset): void
{
if (!is_string($offset)) {
throw new FilesystemException();
}
unset($this->context[$offset]);
}
public function offsetGet(mixed $offset): mixed
{
if (!is_string($offset)) {
throw new FilesystemException();
}
return $this->context[$offset] ?? null;
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->context);
}
}