mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKit.git
synced 2026-01-15 00:35:08 +08:00
feat(utils): 增加了转换存储空间大小的函数
byte -> b/kb/mb/gb/tb/pb Signed-off-by: 李东云 <dongyun.li@luxcreo.ai>
This commit is contained in:
@@ -8,6 +8,8 @@ use Generator;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
@@ -93,7 +95,7 @@ class UtilsService
|
||||
$link_list = explode(',', $link);
|
||||
$link_list = array_map('trim', $link_list);
|
||||
}
|
||||
array_push($link_list, "<$urlReference>; " . http_build_query($params, '', '; '));
|
||||
$link_list[] = "<$urlReference>; " . http_build_query($params, '', '; ');
|
||||
|
||||
return $response->withHeader(
|
||||
'Link',
|
||||
@@ -216,8 +218,35 @@ class UtilsService
|
||||
$list = $list[$childrenName];
|
||||
$end_time = microtime(true);
|
||||
$this->logger->debug("快速无极分类循环{$current_times}次,数组元素数量$max_times");
|
||||
|
||||
|
||||
$cost_time = ($end_time - $start_time) * 1000;
|
||||
$this->logger->debug("快速无极分类用时{$cost_time}ms");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将内存/硬盘大小转化为带单位大小
|
||||
*
|
||||
* @param float|int|string $size 空间大小(单位:Byte)
|
||||
* @param bool $unitToUpper 单位转换为大写(默认 false)
|
||||
* @param int $precision 小数点后保留的位数(默认 2)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
#[
|
||||
ArrayShape(['size' => 'float', 'unit' => 'string']),
|
||||
Pure
|
||||
]
|
||||
public function convertMemorySize(
|
||||
float|int|string $size,
|
||||
bool $unitToUpper = false,
|
||||
int $precision = 2
|
||||
): array {
|
||||
$unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
|
||||
$i = floor(log($size, 1024));
|
||||
return [
|
||||
'size' => round($size / pow(1024, $i), $precision),
|
||||
'unit' => $unitToUpper ? strtoupper($unit[$i]) : $unit[$i],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user