1 | <?php |
||
26 | abstract class AbstractResource implements \ArrayAccess |
||
27 | { |
||
28 | /** |
||
29 | * The resource content |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $content = array(); |
||
34 | |||
35 | /** |
||
36 | * Sets the resource contents |
||
37 | * |
||
38 | * @param array $content |
||
39 | * |
||
40 | * @return $this |
||
41 | */ |
||
42 | 1 | public function setContent($content) |
|
47 | |||
48 | /** |
||
49 | * Returns the content of the resource |
||
50 | * |
||
51 | * @return array The content |
||
52 | */ |
||
53 | 66 | public function getContent() |
|
57 | |||
58 | /** |
||
59 | * Normal `$example[$key]` access for the array |
||
60 | * |
||
61 | * @param mixed $key The key to get the value for |
||
62 | * |
||
63 | * @return array|bool|null The resource key value |
||
64 | */ |
||
65 | 4 | public function offsetGet($key) |
|
69 | |||
70 | /** |
||
71 | * Object oriented get access for the array |
||
72 | * |
||
73 | * @param mixed $key The key to get the value for |
||
74 | * |
||
75 | * @return array|bool|null The resource key value |
||
76 | */ |
||
77 | 9 | public function get($key) |
|
81 | |||
82 | /** |
||
83 | * The internal get function for getting values by their key |
||
84 | * |
||
85 | * @param array $array The array to use -- will always be $this->content |
||
86 | * @param mixed $key The key to find the value for |
||
87 | * @param bool $exists Whether to return null or false dependant on the calling function |
||
88 | * |
||
89 | * @return array|bool|null The resource key value |
||
90 | */ |
||
91 | 9 | private function internalGet(array $array, $key, $exists = false) |
|
109 | |||
110 | /** |
||
111 | * Normal `$example[$key] = 'hello'` access for the array |
||
112 | * |
||
113 | * @param mixed $key The key to set the value for |
||
114 | * @param mixed $value The value to set |
||
115 | */ |
||
116 | 2 | public function offsetSet($key, $value) |
|
120 | |||
121 | /** |
||
122 | * Object oriented set access for the array |
||
123 | * |
||
124 | * @param string $key The key to set the value for |
||
125 | * @param string $value The value to set |
||
126 | */ |
||
127 | 57 | public function set($key, $value) |
|
131 | |||
132 | /** |
||
133 | * Object oriented set access for the array |
||
134 | * |
||
135 | * @param array $array The array to use -- will always be based on $this->content but can be used recursively |
||
136 | * @param mixed $key The key to set the value for |
||
137 | * @param mixed $value The value to set |
||
138 | * |
||
139 | * @return array Returns the modified array |
||
140 | */ |
||
141 | 57 | private function internalSet(array &$array, $key, $value) |
|
163 | |||
164 | /** |
||
165 | * Checks whether the key exists |
||
166 | * |
||
167 | * @param mixed $key The key to check |
||
168 | * |
||
169 | * @return bool Does the key exist |
||
170 | */ |
||
171 | 2 | public function offsetExists($key) |
|
175 | |||
176 | /** |
||
177 | * Unsets the key |
||
178 | * |
||
179 | * @param mixed $key The key to unset |
||
180 | */ |
||
181 | 2 | public function offsetUnset($key) |
|
185 | |||
186 | /** |
||
187 | * Internal unset for the key |
||
188 | * |
||
189 | * @param array $array The array to use -- will always be based on $this->content but can be used recursively |
||
190 | * @param mixed $key The key to unset |
||
191 | */ |
||
192 | 2 | protected function internalUnset(array &$array, $key) |
|
206 | |||
207 | /** |
||
208 | * Port of array_key_exists to \ArrayAccess |
||
209 | * |
||
210 | * @param mixed $key The key to check if exists |
||
211 | * |
||
212 | * @return bool Does the key exist |
||
213 | */ |
||
214 | 4 | public function arrayKeyExists($key) |
|
232 | } |
||
233 |