Show database size in system info tool

This commit is contained in:
Jan Böhmer 2023-01-16 00:06:14 +01:00
parent 706253ce74
commit 6eb40c6a41
4 changed files with 47 additions and 0 deletions

View file

@ -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];
}
}