|
17 | 17 | use Illuminate\Support\Arr; |
18 | 18 | use Illuminate\Support\Facades\Log; |
19 | 19 |
|
| 20 | +if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\env_explode')) { |
| 21 | + /** |
| 22 | + * @noinspection LaravelFunctionsInspection |
| 23 | + */ |
| 24 | + function env_explode(string $key, mixed $default = null, string $delimiter = ',', int $limit = \PHP_INT_MAX): mixed |
| 25 | + { |
| 26 | + $env = env($key, $default); |
| 27 | + |
| 28 | + if (\is_string($env)) { |
| 29 | + return $env ? explode($delimiter, $env, $limit) : []; |
| 30 | + } |
| 31 | + |
| 32 | + return $env; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\json_pretty_encode')) { |
| 37 | + /** |
| 38 | + * @param int<1, 4194304> $depth |
| 39 | + * |
| 40 | + * @throws \JsonException |
| 41 | + */ |
| 42 | + function json_pretty_encode(mixed $value, int $options = 0, int $depth = 512): string |
| 43 | + { |
| 44 | + return json_encode( |
| 45 | + $value, |
| 46 | + \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR | \JSON_FORCE_OBJECT | $options, |
| 47 | + $depth |
| 48 | + ); |
| 49 | + } |
| 50 | +} |
| 51 | + |
20 | 52 | if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\make')) { |
21 | 53 | /** |
22 | 54 | * @see https://github.com/laravel/framework/blob/12.x/src/Illuminate/Foundation/helpers.php |
@@ -80,67 +112,3 @@ function rescue(callable $callback, mixed $rescue = null, mixed $log = true): mi |
80 | 112 | } |
81 | 113 | } |
82 | 114 | } |
83 | | - |
84 | | -if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\env_explode')) { |
85 | | - /** |
86 | | - * @noinspection LaravelFunctionsInspection |
87 | | - */ |
88 | | - function env_explode(string $key, mixed $default = null, string $delimiter = ',', int $limit = \PHP_INT_MAX): mixed |
89 | | - { |
90 | | - $env = env($key, $default); |
91 | | - |
92 | | - if (\is_string($env)) { |
93 | | - return $env ? explode($delimiter, $env, $limit) : []; |
94 | | - } |
95 | | - |
96 | | - return $env; |
97 | | - } |
98 | | -} |
99 | | - |
100 | | -if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\json_pretty_encode')) { |
101 | | - /** |
102 | | - * @param int<1, 4194304> $depth |
103 | | - * |
104 | | - * @throws \JsonException |
105 | | - */ |
106 | | - function json_pretty_encode(mixed $value, int $options = 0, int $depth = 512): string |
107 | | - { |
108 | | - return json_encode( |
109 | | - $value, |
110 | | - \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR | \JSON_FORCE_OBJECT | $options, |
111 | | - $depth |
112 | | - ); |
113 | | - } |
114 | | -} |
115 | | - |
116 | | -if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\human_bytes')) { |
117 | | - /** |
118 | | - * @see https://stackoverflow.com/a/23888858/1580028 |
119 | | - */ |
120 | | - function human_bytes(int $bytes, int $decimals = 2): string |
121 | | - { |
122 | | - $size = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; |
123 | | - $factor = (int) floor((\strlen((string) $bytes) - 1) / 3); |
124 | | - |
125 | | - if (0 === $factor) { |
126 | | - $decimals = 0; |
127 | | - } |
128 | | - |
129 | | - return \sprintf("%.{$decimals}f %s", $bytes / (1024 ** $factor), $size[$factor]); |
130 | | - } |
131 | | -} |
132 | | - |
133 | | -if (!\function_exists('Guanguans\LaravelExceptionNotify\Support\human_milliseconds')) { |
134 | | - function human_milliseconds(float $milliseconds, int $precision = 2): string |
135 | | - { |
136 | | - if (1 > $milliseconds) { |
137 | | - return \sprintf('%s μs', round($milliseconds * 1000, $precision)); |
138 | | - } |
139 | | - |
140 | | - if (1000 > $milliseconds) { |
141 | | - return \sprintf('%s ms', round($milliseconds, $precision)); |
142 | | - } |
143 | | - |
144 | | - return \sprintf('%s s', round($milliseconds / 1000, $precision)); |
145 | | - } |
146 | | -} |
0 commit comments