mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
draft torrent info page with related features #11
This commit is contained in:
parent
21ffd8aa01
commit
387acb59b6
7 changed files with 349 additions and 5 deletions
55
src/Twig/AppExtension.php
Normal file
55
src/Twig/AppExtension.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
protected $container;
|
||||
|
||||
public function __construct(
|
||||
ContainerInterface $container
|
||||
)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return
|
||||
[
|
||||
new TwigFilter(
|
||||
'format_bytes',
|
||||
[
|
||||
$this,
|
||||
'formatBytes'
|
||||
]
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function formatBytes(
|
||||
int $bytes,
|
||||
int $precision = 2
|
||||
) : string
|
||||
{
|
||||
$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];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue