misc_pterodactyl-panel/app/Providers/MacroServiceProvider.php

29 lines
676 B
PHP
Raw Normal View History

<?php
2016-12-07 22:46:38 +00:00
2017-03-16 00:52:37 +00:00
namespace Pterodactyl\Providers;
2018-03-02 00:43:39 +00:00
use Illuminate\Support\Facades\File;
2017-03-16 00:52:37 +00:00
use Illuminate\Support\ServiceProvider;
2017-03-16 00:52:37 +00:00
class MacroServiceProvider extends ServiceProvider
2016-12-07 22:46:38 +00:00
{
/**
2017-03-16 00:52:37 +00:00
* Bootstrap the application services.
*/
2017-03-16 00:52:37 +00:00
public function boot()
{
2017-03-16 00:52:37 +00:00
File::macro('humanReadableSize', function ($path, $precision = 2) {
$size = File::size($path);
static $units = ['B', 'kB', 'MB', 'GB', 'TB'];
$i = 0;
while (($size / 1024) > 0.9) {
$size = $size / 1024;
$i++;
2017-03-16 00:52:37 +00:00
}
return round($size, ($i < 2) ? 0 : $precision) . ' ' . $units[$i];
});
}
}