2016-10-14 20:20:24 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-03-16 00:52:37 +00:00
|
|
|
namespace Pterodactyl\Providers;
|
2016-10-14 20:20:24 +00:00
|
|
|
|
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;
|
2016-10-14 20:20:24 +00:00
|
|
|
|
2017-03-16 00:52:37 +00:00
|
|
|
class MacroServiceProvider extends ServiceProvider
|
2016-12-07 22:46:38 +00:00
|
|
|
{
|
2016-10-14 20:20:24 +00:00
|
|
|
/**
|
2017-03-16 00:52:37 +00:00
|
|
|
* Bootstrap the application services.
|
2016-10-14 20:20:24 +00:00
|
|
|
*/
|
2017-03-16 00:52:37 +00:00
|
|
|
public function boot()
|
2016-10-14 20:20:24 +00:00
|
|
|
{
|
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;
|
2017-11-05 18:59:51 +00:00
|
|
|
$i++;
|
2017-03-16 00:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return round($size, ($i < 2) ? 0 : $precision) . ' ' . $units[$i];
|
|
|
|
});
|
2016-10-14 20:20:24 +00:00
|
|
|
}
|
|
|
|
}
|