| 1 |
<?php |
| 2 |
|
| 3 |
use App\Billingo\Service\BillingoCollection; |
| 4 |
use App\Billingo\Service\BillingoTranslator; |
| 5 |
use App\Billingo\WooCommerce\Service\Billingo_View; |
| 6 |
use Symfony\Component\VarDumper\VarDumper; |
| 7 |
|
| 8 |
if (!function_exists('getEnumValues')) { |
| 9 |
function getEnumValues(string $enum): array |
| 10 |
{ |
| 11 |
return array_map(fn($enum) => $enum->value, $enum::cases()); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
if (!function_exists('get_wp_translated_enum')) { |
| 16 |
function get_wp_translated_enum(string $enum, bool $wp_translate = false): array |
| 17 |
{ |
| 18 |
$translated = []; |
| 19 |
|
| 20 |
foreach ($enum::cases() as $enum) { |
| 21 |
$translated[$enum->value] = $wp_translate |
| 22 |
? __($enum->getReadableText(), 'billingo') |
| 23 |
: $enum->getReadableText(); |
| 24 |
} |
| 25 |
|
| 26 |
return $translated; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
if (!function_exists('classBasename')) { |
| 31 |
function classBasename($class): string |
| 32 |
{ |
| 33 |
if (is_object($class)) { |
| 34 |
$class = get_class($class); |
| 35 |
} |
| 36 |
|
| 37 |
return basename(str_replace('\\', '/', $class)); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
if (!function_exists('dd')) { |
| 42 |
function dd(mixed ...$vars): never |
| 43 |
{ |
| 44 |
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) && !headers_sent()) { |
| 45 |
header('HTTP/1.1 500 Internal Server Error'); |
| 46 |
} |
| 47 |
|
| 48 |
if (array_key_exists(0, $vars) && 1 === count($vars)) { |
| 49 |
VarDumper::dump($vars[0]); |
| 50 |
} else { |
| 51 |
foreach ($vars as $k => $v) { |
| 52 |
VarDumper::dump($v, is_int($k) ? 1 + $k : $k); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
exit(1); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
if (!function_exists('camelToSnake')) { |
| 61 |
function camelToSnake(string $input): string |
| 62 |
{ |
| 63 |
$snake = preg_replace('/[A-Z]/', '_$0', $input); |
| 64 |
|
| 65 |
$snake = strtolower($snake); |
| 66 |
|
| 67 |
if (str_starts_with($snake, '_')) { |
| 68 |
$snake = substr($snake, 1); |
| 69 |
} |
| 70 |
|
| 71 |
return $snake; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
if (!function_exists('trans')) { |
| 76 |
function trans(string $key): string |
| 77 |
{ |
| 78 |
$translator = BillingoTranslator::getInstance(); |
| 79 |
|
| 80 |
return $translator->translate($key); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
if (!function_exists('view')) { |
| 85 |
function view(string $key, array $content = []): string |
| 86 |
{ |
| 87 |
$view = Billingo_View::getInstance(); |
| 88 |
|
| 89 |
return $view->getViewContent($key, $content); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
if (!function_exists('isArraySubset')) { |
| 94 |
function isArraySubset(array $subset, array $set): bool |
| 95 |
{ |
| 96 |
foreach ($subset as $key => $value) { |
| 97 |
if (is_array($value)) { |
| 98 |
if (!isset($set[$key]) || !is_array($set[$key]) || !isArraySubset($value, $set[$key])) { |
| 99 |
|
| 100 |
return false; |
| 101 |
} |
| 102 |
} else { |
| 103 |
if (!array_key_exists($key, $set) || $set[$key] != $value) { |
| 104 |
|
| 105 |
return false; |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
return true; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
if (!function_exists('billingoCollection')) { |
| 115 |
function billingoCollection(array $collection): BillingoCollection |
| 116 |
{ |
| 117 |
return new BillingoCollection($collection); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
if (!function_exists('wcFlexibleIsTrue')) { |
| 123 |
function wcFlexibleIsTrue($value): bool |
| 124 |
{ |
| 125 |
return in_array(strtolower($value), ['1', 'yes', 'true', 'on'], true); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
|