1 | <?php |
||
26 | class GetterHelper |
||
27 | { |
||
28 | /** |
||
29 | * Get some data by pretty name |
||
30 | * |
||
31 | * @param array|object $data data for pretty access |
||
32 | * @param string $name name for access |
||
33 | * @param bool $safe if true - Exception for not exist fields |
||
34 | * @return mixed |
||
35 | * @throws \UnexpectedValueException |
||
36 | */ |
||
37 | public static function get($data, string $name, bool $safe = true) |
||
45 | |||
46 | /** |
||
47 | * Get iterator for data |
||
48 | * |
||
49 | * @param mixed $data |
||
50 | * @return \Traversable |
||
51 | */ |
||
52 | public static function getIterator($data): \Traversable |
||
62 | |||
63 | /** |
||
64 | * Get keys list for data |
||
65 | * |
||
66 | * @param mixed $data |
||
67 | * @return array |
||
68 | */ |
||
69 | public static function getKeys($data) : array |
||
86 | |||
87 | /** |
||
88 | * One level get |
||
89 | * |
||
90 | * @param type $data |
||
91 | * @param string $key |
||
92 | * @param bool $safe |
||
93 | * @return mixed |
||
94 | * @throws \UnexpectedValueException |
||
95 | */ |
||
96 | protected static function subGet($data, string $key, bool $safe = true) |
||
117 | |||
118 | /** |
||
119 | * Check if data is array or ArrayAccess |
||
120 | * @param type $data |
||
121 | * @return bool |
||
122 | */ |
||
123 | protected static function isArrayable($data) : bool |
||
127 | |||
128 | /** |
||
129 | * Check if key is methods name (i.e. finished to "()") |
||
130 | * and return methods name |
||
131 | * |
||
132 | * @param string $key |
||
133 | * @return string|null |
||
134 | */ |
||
135 | protected static function tryGetMethodName(string $key) : ?string |
||
142 | } |
||
143 |