1 | <?php |
||
14 | class KeyValuePair implements \ArrayAccess |
||
15 | { |
||
16 | /** @var mixed */ |
||
17 | public $key; |
||
18 | |||
19 | /** @var mixed */ |
||
20 | public $value; |
||
21 | |||
22 | /** |
||
23 | * Pair constructor. |
||
24 | * |
||
25 | * @param mixed $key |
||
26 | * @param mixed $value |
||
27 | */ |
||
28 | 3 | public function __construct($key = null, $value = null) |
|
33 | |||
34 | /** |
||
35 | * @{inheritDoc} |
||
36 | */ |
||
37 | 3 | public function offsetExists($offset) |
|
38 | { |
||
39 | 3 | return in_array($offset, [0, 1, 'key', 'value']); |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @{inheritDoc} |
||
44 | */ |
||
45 | 3 | public function offsetGet($offset) |
|
46 | { |
||
47 | 3 | if ($offset === 0 || $offset === 'key') { |
|
48 | 3 | return $this->key; |
|
49 | } |
||
50 | |||
51 | 3 | if ($offset === 1 || $offset === 'value') { |
|
52 | 3 | return $this->value; |
|
53 | } |
||
54 | |||
55 | throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"'); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @{inheritDoc} |
||
60 | */ |
||
61 | public function offsetSet($offset, $value) |
||
73 | |||
74 | /** |
||
75 | * @{inheritDoc} |
||
76 | */ |
||
77 | public function offsetUnset($offset) |
||
81 | } |
||
82 |