mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +02:00
Show database size in system info tool
This commit is contained in:
parent
706253ce74
commit
6eb40c6a41
4 changed files with 47 additions and 0 deletions
|
@ -86,6 +86,8 @@ final class FormatExtension extends AbstractExtension
|
|||
new TwigFilter('format_si', [$this, 'siFormat']),
|
||||
/** Format the given amount using the given MeasurementUnit */
|
||||
new TwigFilter('format_amount', [$this, 'amountFormat']),
|
||||
/** Format the given number of bytes as human readable number */
|
||||
new TwigFilter('format_bytes', [$this, 'formatBytes']),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -107,4 +109,16 @@ final class FormatExtension extends AbstractExtension
|
|||
{
|
||||
return $this->amountFormatter->format($value, $unit, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bytes
|
||||
* @param int $precision
|
||||
* @return string
|
||||
*/
|
||||
public function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
|
||||
$factor = floor((strlen((string) $bytes) - 1) / 3);
|
||||
return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue