1 | <?php |
||
20 | class ArrayHelper |
||
21 | { |
||
22 | const USAGE_EXISTS = 'hasKey'; |
||
23 | const USAGE_EXTRACT = 'getValue'; |
||
24 | |||
25 | /** |
||
26 | * Verify if a key exist in depth |
||
27 | * |
||
28 | * @param array $haystack - The array in which to search |
||
29 | * @param array $keys - an array with the linear items treated as depth. |
||
30 | * Ex: array('first_level','second_level','third_level') |
||
31 | * @return bool |
||
32 | * @throws \NeedleProject\Common\Exception\NotFoundException |
||
33 | */ |
||
34 | 11 | public function hasKeysInDepth($haystack, $keys) |
|
39 | |||
40 | /** |
||
41 | * Get a value in depth of an array |
||
42 | * |
||
43 | * @param array $haystack - The array in which to search |
||
44 | * @param array $keys - an array with the linear items treated as depth. |
||
45 | * Ex: array('first_level','second_level','third_level') |
||
46 | * @return mixed |
||
47 | * @throws \NeedleProject\Common\Exception\NotFoundException |
||
48 | */ |
||
49 | 10 | public function getValueFromDepth($haystack, $keys) |
|
54 | |||
55 | /** |
||
56 | * @param array $haystack |
||
57 | * @param array $keys |
||
58 | * @param string $searchType Added search type to reuse the same code |
||
59 | * even if it increases the complexity (for ~20 line) |
||
60 | * @throws \NeedleProject\Common\Exception\NotFoundException |
||
61 | * @return mixed |
||
62 | */ |
||
63 | 7 | private function getNode($haystack, $keys, $searchType) |
|
84 | |||
85 | /** |
||
86 | * Validate if the given input are valid array |
||
87 | * @param array $haystack |
||
88 | * @param array $keys |
||
89 | */ |
||
90 | 21 | private function validateInput($haystack, $keys) |
|
103 | } |
||
104 |