PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Util / Arr.php

Arr.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/sentry/sentry/src/Util/Arr.php

68 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry\Util;
5
6 /**
7 * This class provides some utility methods to work with arrays.
8 *
9 * @internal
10 */
11 class Arr
12 {
13 /**
14 * Flatten a multi-dimensional associative array with dots except for keys that contain lists.
15 *
16 * This method is similar to Laravel's `Arr::dot()` method but does not flatten lists.
17 * See: https://github.com/laravel/framework/blob/1bfad3020ec5d542ac7352c6fd0d388cbe29c46c/src/Illuminate/Collections/Arr.php#L163
18 *
19 * @param array<string, mixed> $array
20 *
21 * @return array<string, mixed>
22 */
23 public static function simpleDot(array $array) : array
24 {
25 $results = [];
26 $flatten = static function ($data, $prefix = '') use(&$results, &$flatten) : void {
27 foreach ($data as $key => $value) {
28 $newKey = $prefix . $key;
29 if (\is_array($value) && !empty($value) && !self::isList($value)) {
30 $flatten($value, $newKey . '.');
31 } else {
32 $results[$newKey] = $value;
33 }
34 }
35 };
36 $flatten($array);
37 return $results;
38 }
39 /**
40 * Checks whether a given array is a list.
41 *
42 * `array_is_list` is introduced in PHP 8.1, so we have a polyfill for it.
43 *
44 * @see https://www.php.net/manual/en/function.array-is-list.php#126794
45 *
46 * @param array<array-key, mixed> $array
47 */
48 public static function isList(array $array) : bool
49 {
50 $i = 0;
51 foreach ($array as $k => $v) {
52 if ($k !== $i++) {
53 return \false;
54 }
55 }
56 return \true;
57 }
58 /**
59 * Checks whether a given value is an associative array.
60 *
61 * @param mixed $value
62 */
63 public static function isAssociative($value) : bool
64 {
65 return \is_array($value) && !self::isList($value);
66 }
67 }
68