mirror of
https://github.com/kevachat/webapp.git
synced 2025-01-23 04:54:32 +00:00
add formatBytes filter
This commit is contained in:
parent
eb57f1bcad
commit
c8ba485edc
@ -31,6 +31,13 @@ class AppExtension extends AbstractExtension
|
|||||||
'formatAgo'
|
'formatAgo'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
new TwigFilter(
|
||||||
|
'format_bytes',
|
||||||
|
[
|
||||||
|
$this,
|
||||||
|
'formatBytes'
|
||||||
|
]
|
||||||
|
),
|
||||||
new TwigFilter(
|
new TwigFilter(
|
||||||
'message_to_markdown',
|
'message_to_markdown',
|
||||||
[
|
[
|
||||||
@ -140,6 +147,28 @@ class AppExtension extends AbstractExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function formatBytes(
|
||||||
|
int $bytes,
|
||||||
|
int $precision = 2
|
||||||
|
): string
|
||||||
|
{
|
||||||
|
$size = [
|
||||||
|
$this->translator->trans('B'),
|
||||||
|
$this->translator->trans('Kb'),
|
||||||
|
$this->translator->trans('Mb'),
|
||||||
|
$this->translator->trans('Gb'),
|
||||||
|
$this->translator->trans('Tb'),
|
||||||
|
$this->translator->trans('Pb'),
|
||||||
|
$this->translator->trans('Eb'),
|
||||||
|
$this->translator->trans('Zb'),
|
||||||
|
$this->translator->trans('Yb')
|
||||||
|
];
|
||||||
|
|
||||||
|
$factor = floor((strlen($bytes) - 1) / 3);
|
||||||
|
|
||||||
|
return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
|
||||||
|
}
|
||||||
|
|
||||||
public function messageToMarkdown(
|
public function messageToMarkdown(
|
||||||
string $text
|
string $text
|
||||||
): string
|
): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user