|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: johnny |
|
5
|
|
|
* Date: 11-04-16 |
|
6
|
|
|
* Time: 23:06 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Redbox\DNS; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class Reflectable implements \ArrayAccess, \Countable |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Data |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
* @access private |
|
19
|
|
|
*/ |
|
20
|
|
|
private $data = []; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Get a data by key |
|
24
|
|
|
* |
|
25
|
|
|
* @param string The key data to retrieve |
|
26
|
|
|
* @access public |
|
27
|
|
|
*/ |
|
28
|
|
|
public function &__get($key) |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->data[$key]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Assigns a value to the specified data |
|
36
|
|
|
* |
|
37
|
|
|
* @param string The data key to assign the value to |
|
38
|
|
|
* @param mixed The value to set |
|
39
|
|
|
* @access public |
|
40
|
|
|
*/ |
|
41
|
16 |
|
public function __set($key, $value) |
|
42
|
|
|
{ |
|
43
|
16 |
|
$this->data[$key] = $value; |
|
44
|
16 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Whether or not an data exists by key |
|
48
|
|
|
* |
|
49
|
|
|
* @param string An data key to check for |
|
50
|
|
|
* @access public |
|
51
|
|
|
* @return boolean |
|
52
|
|
|
* @abstracting ArrayAccess |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __isset($key) |
|
55
|
|
|
{ |
|
56
|
|
|
return isset($this->data[$key]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Unsets an data by key |
|
61
|
|
|
* |
|
62
|
|
|
* @param string The key to unset |
|
63
|
|
|
* @access public |
|
64
|
|
|
*/ |
|
65
|
|
|
public function __unset($key) |
|
66
|
|
|
{ |
|
67
|
|
|
unset($this->data[$key]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Assigns a value to the specified offset |
|
72
|
|
|
* |
|
73
|
|
|
* @param string The offset to assign the value to |
|
74
|
|
|
* @param mixed The value to set |
|
75
|
|
|
* @access public |
|
76
|
|
|
* @abstracting ArrayAccess |
|
77
|
|
|
*/ |
|
78
|
|
|
public function offsetSet($offset, $value) |
|
79
|
|
|
{ |
|
80
|
|
|
if (is_null($offset)) { |
|
81
|
|
|
$this->data[] = $value; |
|
82
|
|
|
} else { |
|
83
|
|
|
$this->data[$offset] = $value; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Whether or not an offset exists |
|
89
|
|
|
* |
|
90
|
|
|
* @param string An offset to check for |
|
91
|
|
|
* @access public |
|
92
|
|
|
* @return boolean |
|
93
|
|
|
* @abstracting ArrayAccess |
|
94
|
|
|
*/ |
|
95
|
4 |
|
public function offsetExists($offset) |
|
96
|
|
|
{ |
|
97
|
4 |
|
return isset($this->data[$offset]); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Unsets an offset |
|
102
|
|
|
* |
|
103
|
|
|
* @param string The offset to unset |
|
104
|
|
|
* @access public |
|
105
|
|
|
* @abstracting ArrayAccess |
|
106
|
|
|
*/ |
|
107
|
|
|
public function offsetUnset($offset) |
|
108
|
|
|
{ |
|
109
|
|
|
if ($this->offsetExists($offset)) { |
|
110
|
|
|
unset($this->data[$offset]); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Returns the value at specified offset |
|
116
|
|
|
* |
|
117
|
|
|
* @param string The offset to retrieve |
|
118
|
|
|
* @access public |
|
119
|
|
|
* @return mixed |
|
120
|
|
|
* @abstracting ArrayAccess |
|
121
|
|
|
*/ |
|
122
|
4 |
|
public function offsetGet($offset) |
|
123
|
|
|
{ |
|
124
|
4 |
|
return $this->offsetExists($offset) ? $this->data[$offset] : null; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
12 |
|
public function clear() |
|
128
|
|
|
{ |
|
129
|
12 |
|
$this->rewind(); |
|
130
|
|
|
|
|
131
|
12 |
|
foreach($this->data as $key => $value) { |
|
132
|
12 |
|
unset($this->data[$key]); |
|
133
|
12 |
|
} |
|
134
|
12 |
|
} |
|
135
|
|
|
|
|
136
|
12 |
|
public function rewind() { |
|
137
|
12 |
|
reset($this->data); |
|
138
|
12 |
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function count() { |
|
141
|
|
|
return count(array_keys($this->data)); |
|
142
|
|
|
} |
|
143
|
|
|
} |