| 1 |
<?php |
| 2 |
|
| 3 |
use UltimateStoreKit\Base\Support\Optional; |
| 4 |
|
| 5 |
if (!function_exists('dd')) { |
| 6 |
|
| 7 |
/** |
| 8 |
* dump & die. |
| 9 |
*/ |
| 10 |
function dd($x) { |
| 11 |
echo '<pre>'; |
| 12 |
if (is_array($x) || is_object($x)) { |
| 13 |
print_r($x); |
| 14 |
} else { |
| 15 |
echo wp_kses_post($x); |
| 16 |
} |
| 17 |
echo '</pre>'; |
| 18 |
exit; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
if (! function_exists('optional')) { |
| 23 |
/** |
| 24 |
* Provide access to optional objects. |
| 25 |
* |
| 26 |
* @param mixed $value |
| 27 |
* @param callable|null $callback |
| 28 |
* @return mixed |
| 29 |
*/ |
| 30 |
function optional($value = null, ?callable $callback = null) { |
| 31 |
if (is_null($callback)) { |
| 32 |
return new Optional($value); |
| 33 |
} elseif (! is_null($value)) { |
| 34 |
return $callback($value); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
if (! function_exists('array_except')) { |
| 41 |
/** |
| 42 |
* Provide access to optional objects. |
| 43 |
* |
| 44 |
* @param mixed $value |
| 45 |
* @param callable|null $callback |
| 46 |
* @return mixed |
| 47 |
*/ |
| 48 |
function array_except($array, $keys) { |
| 49 |
|
| 50 |
$original = &$array; |
| 51 |
|
| 52 |
$keys = (array) $keys; |
| 53 |
|
| 54 |
if (count($keys) === 0) { |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
foreach ($keys as $key) { |
| 59 |
// if the exact key exists in the top-level, remove it |
| 60 |
if (array_key_exists($key, $array)) { |
| 61 |
unset($array[$key]); |
| 62 |
|
| 63 |
continue; |
| 64 |
} |
| 65 |
|
| 66 |
$parts = explode('.', $key); |
| 67 |
|
| 68 |
// clean up before each pass |
| 69 |
$array = &$original; |
| 70 |
|
| 71 |
while (count($parts) > 1) { |
| 72 |
$part = array_shift($parts); |
| 73 |
|
| 74 |
if (isset($array[$part]) && is_array($array[$part])) { |
| 75 |
$array = &$array[$part]; |
| 76 |
} else { |
| 77 |
continue 2; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
unset($array[array_shift($parts)]); |
| 82 |
} |
| 83 |
|
| 84 |
return $array; |
| 85 |
} |
| 86 |
} |
| 87 |
|