mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-19 21:04:44 +02:00

* Fix these * Update phpstan * Transform these into their identifiers instead * Fix custom rule * License is wrong * Update these * Pint fixes * Fix this * Consolidate these * Never supported PHP 7 * Better evaluation * Fixes * Don’t need ignore * Replace trait with service * Subusers are simply the many to many relationship between Servers and Users * Adjust to remove ignores * Use new query builder instead! * wip * Update composer * Quick fixes * Use realtime facade * Small fixes * Convert to static to avoid new * Update to statics * Don’t modify protected properties directly * Run pint * Change to correct method * Give up and use the facade * Make sure this route is available * Filament hasn’t been loaded yet * This can be readonly * Typehint * These are no longer used * Quick fixes * Need doc block help * Always true * We use caddy with docker * Pint * Fix phpstan issues * Remove unused import --------- Co-authored-by: MartinOscar <40749467+RMartinOscar@users.noreply.github.com>
70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
if (!function_exists('is_digit')) {
|
|
/**
|
|
* Deal with normal (and irritating) PHP behavior to determine if
|
|
* a value is a non-float positive integer.
|
|
*/
|
|
function is_digit(mixed $value): bool
|
|
{
|
|
return !is_bool($value) && ctype_digit(strval($value));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('is_ip')) {
|
|
function is_ip(?string $address): bool
|
|
{
|
|
return $address !== null && filter_var($address, FILTER_VALIDATE_IP) !== false;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('convert_bytes_to_readable')) {
|
|
function convert_bytes_to_readable(int $bytes, int $decimals = 2, ?int $base = null): string
|
|
{
|
|
$conversionUnit = config('panel.use_binary_prefix') ? 1024 : 1000;
|
|
$suffix = config('panel.use_binary_prefix') ? ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'] : ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
if ($bytes <= 0) {
|
|
return '0 ' . $suffix[0];
|
|
}
|
|
|
|
$fromBase = log($bytes) / log($conversionUnit);
|
|
$base ??= floor($fromBase);
|
|
|
|
return round(pow($conversionUnit, $fromBase - $base), $decimals) . ' ' . $suffix[$base];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('join_paths')) {
|
|
function join_paths(string $base, string ...$paths): string
|
|
{
|
|
if ($base === '/') {
|
|
return str_replace('//', '', implode('/', $paths));
|
|
}
|
|
|
|
return str_replace('//', '', $base . '/' . implode('/', $paths));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('resolve_path')) {
|
|
function resolve_path(string $path): string
|
|
{
|
|
$parts = array_filter(explode('/', $path), fn (string $p) => strlen($p) > 0);
|
|
|
|
$absolutes = [];
|
|
foreach ($parts as $part) {
|
|
if ($part == '.') {
|
|
continue;
|
|
}
|
|
|
|
if ($part == '..') {
|
|
array_pop($absolutes);
|
|
} else {
|
|
$absolutes[] = $part;
|
|
}
|
|
}
|
|
|
|
return implode('/', $absolutes);
|
|
}
|
|
}
|