First version

This commit is contained in:
2023-05-26 11:47:40 +00:00
commit 6294487276
10 changed files with 1383 additions and 0 deletions

30
src/Twig/AppExtension.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace App\Twig;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return array(
new TwigFilter('formatBytes', array($this, 'formatBytes')),
);
}
/**
* @param $bytes
* @param int $precision
* @return string
*/
public function formatBytes($bytes, $precision = 2)
{
$size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$precision}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
}