1 | <?php |
||
23 | trait DataTrait |
||
24 | { |
||
25 | /** |
||
26 | * Internal data storage. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $data = []; |
||
31 | |||
32 | /** |
||
33 | * Clears the data(!) content of the object. |
||
34 | * |
||
35 | * @return $this |
||
36 | */ |
||
37 | public function clear() |
||
43 | |||
44 | /** |
||
45 | * Generic set method for multidimensional storage. |
||
46 | * |
||
47 | * $this->set( $key1, $key2, $key3, ..., $val ) |
||
48 | * |
||
49 | * @throws InvalidParameterSetException |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function set() |
||
80 | |||
81 | /** |
||
82 | * Set list of key/value pairs via one dimensional array. |
||
83 | * Careful: An empty array will just overwrite your internal storage. |
||
84 | * |
||
85 | * @param array $param |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function setByArray(array $param) |
||
102 | |||
103 | /** |
||
104 | * Adds given object's properties to self. |
||
105 | * |
||
106 | * @param object $param |
||
107 | * @return $this |
||
108 | * @throws InvalidParameterException |
||
109 | */ |
||
110 | public function setByObject($param) |
||
132 | |||
133 | /** |
||
134 | * Fill datastore from json string. |
||
135 | * |
||
136 | * @param string $json |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function setByJson(string $json) |
||
147 | |||
148 | /** |
||
149 | * Return stored data array. |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | public function toArray() : array |
||
157 | |||
158 | /** |
||
159 | * Convert internal data to json. |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | public function toJson() : string |
||
167 | |||
168 | /** |
||
169 | * Multidimensional getter. |
||
170 | * |
||
171 | * Find a key structure in a multidimensional array and return the value |
||
172 | * params are stackable -> get( $k1, $k2, $k3, ... ). |
||
173 | * |
||
174 | * @return bool|mixed |
||
175 | */ |
||
176 | public function get() |
||
183 | |||
184 | /** |
||
185 | * Return all keys of internal array's first level. |
||
186 | * |
||
187 | * @return array keylist |
||
188 | */ |
||
189 | public function getKeys() : array |
||
193 | |||
194 | /** |
||
195 | * Remove key from container. |
||
196 | * |
||
197 | * @param string $key |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function remove(string $key) |
||
208 | |||
209 | /** |
||
210 | * Return count of all firstlevel elements. |
||
211 | * |
||
212 | * @return int |
||
213 | */ |
||
214 | public function count() : int |
||
218 | |||
219 | /** |
||
220 | * Find a key in an array. |
||
221 | * example self::findInArray(array(), key1, key2, key3, ..., default_return) |
||
222 | * |
||
223 | * @return array|bool|mixed |
||
224 | */ |
||
225 | public static function findInArray() |
||
235 | |||
236 | /** |
||
237 | * Search an array for keys (args) and provide a default value if |
||
238 | * last arg is some kind of empty or not numeric. |
||
239 | * |
||
240 | * @param array $args |
||
241 | * @param array $data |
||
242 | * @param bool $default |
||
243 | * @return array|mixed |
||
244 | */ |
||
245 | private static function searchArray(array $args, array $data, $default = false) |
||
269 | } |
||
270 |