1111
1212use ArrayAccess ;
1313use Toolkit \Stdlib \Php ;
14- use Traversable ;
1514use function array_filter ;
1615use function array_shift ;
1716use function count ;
@@ -32,9 +31,9 @@ trait ArrayValueGetSetTrait
3231 /**
3332 * Add an element to an array using "dot" notation if it doesn't exist.
3433 *
35- * @param array $array
34+ * @param array $array
3635 * @param string $key
37- * @param mixed $value
36+ * @param mixed $value
3837 *
3938 * @return array
4039 */
@@ -81,9 +80,9 @@ public static function get(ArrayAccess|array $array, string $key, mixed $default
8180 * Set an array item to a given value using "dot" notation.
8281 * If no key is given to the method, the entire array will be replaced.
8382 *
84- * @param array $array
83+ * @param array $array
8584 * @param string $key
86- * @param mixed $value
85+ * @param mixed $value
8786 *
8887 * @return array
8988 */
@@ -114,9 +113,8 @@ public static function set(array &$array, string $key, mixed $value): array
114113 /**
115114 * Get Multi - 获取多个, 可以设置默认值
116115 *
117- * @param array $data array data
118- * @param array $needKeys
119- * $needKeys = [
116+ * @param array $data array data
117+ * @param array $needKeys = [
120118 * 'name',
121119 * 'password',
122120 * 'status' => '1'
@@ -131,7 +129,7 @@ public static function gets(array &$data, array $needKeys = [], bool $unsetKey =
131129
132130 foreach ($ needKeys as $ key => $ default ) {
133131 if (is_int ($ key )) {
134- $ key = $ default ;
132+ $ key = $ default ;
135133 $ default = null ;
136134 }
137135
@@ -163,14 +161,14 @@ public static function gets(array &$data, array $needKeys = [], bool $unsetKey =
163161 * Get data from array or object by path.
164162 * Example: `DataCollector::getByPath($array, 'foo.bar.yoo')` equals to $array['foo']['bar']['yoo'].
165163 *
166- * @param Traversable|array $data An array or object to get value.
167- * @param string $path The key path.
164+ * @param iterable $data An array or object to get value.
165+ * @param string $path The key path.
168166 * @param mixed|null $default
169- * @param string $separator Separator of paths.
167+ * @param string $separator Separator of paths.
170168 *
171169 * @return mixed Found value, null if not exists.
172170 */
173- public static function getByPath (Traversable | array $ data , string $ path , mixed $ default = null , string $ separator = '. ' ): mixed
171+ public static function getByPath (iterable $ data , string $ path , mixed $ default = null , string $ separator = '. ' ): mixed
174172 {
175173 if (isset ($ data [$ path ])) {
176174 return $ data [$ path ];
@@ -224,12 +222,12 @@ public static function getValueByNodes(array $data, array $nodes, mixed $default
224222 /**
225223 * setByPath
226224 *
227- * @param ArrayAccess| array & $data
228- * @param string $path
229- * @param mixed $value
230- * @param string $separator
225+ * @param array $data
226+ * @param string $path
227+ * @param mixed $value
228+ * @param string $separator
231229 */
232- public static function setByPath (ArrayAccess | array &$ data , string $ path , mixed $ value , string $ separator = '. ' ): void
230+ public static function setByPath (array &$ data , string $ path , mixed $ value , string $ separator = '. ' ): void
233231 {
234232 if (!str_contains ($ path , $ separator )) {
235233 $ data [$ path ] = $ value ;
0 commit comments