1 | <?php |
||
2 | |||
3 | namespace Nip\Collections\Traits; |
||
4 | |||
5 | /** |
||
6 | * Class ArrayAccessTrait |
||
7 | * @package Nip\Collections |
||
8 | */ |
||
9 | trait ArrayAccessTrait |
||
10 | { |
||
11 | /** |
||
12 | * Determine if the given configuration option exists. |
||
13 | * |
||
14 | * @param string $key |
||
15 | * @return bool |
||
16 | */ |
||
17 | public function offsetExists($key) |
||
18 | 2 | { |
|
19 | return isset($this->items[$key]) || array_key_exists($key, $this->items); |
||
20 | 2 | } |
|
21 | |||
22 | /** |
||
23 | * Get a configuration option. |
||
24 | * |
||
25 | * @param string $key |
||
26 | * @return mixed |
||
27 | */ |
||
28 | public function offsetGet($key) |
||
29 | 4 | { |
|
30 | return $this->items[$key]; |
||
31 | 4 | } |
|
32 | |||
33 | /** |
||
34 | * @param string $key |
||
35 | * @param mixed $value |
||
36 | * @return void |
||
37 | */ |
||
38 | public function offsetSet($key, $value) |
||
39 | 22 | { |
|
40 | if (is_null($key)) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
41 | 22 | $this->items[] = $value; |
|
42 | 16 | } else { |
|
43 | $this->items[$key] = $value; |
||
0 ignored issues
–
show
|
|||
44 | 20 | } |
|
45 | } |
||
46 | 22 | ||
47 | /** |
||
48 | * Unset a configuration option. |
||
49 | * |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | public function offsetUnset($key) |
||
53 | 1 | { |
|
54 | unset($this->items[$key]); |
||
55 | 1 | } |
|
56 | } |
||
57 |