mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
32 lines
937 B
PHP
32 lines
937 B
PHP
<?php
|
|
namespace App\Users\Actions;
|
|
|
|
use ByteUnits\Metric;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class FormatUsageEstimatesAction
|
|
{
|
|
public function __invoke(string $currency, Collection $usage)
|
|
{
|
|
return $usage->mapWithKeys(function ($estimate) use ($currency) {
|
|
// Format usage
|
|
$usage = match ($estimate['feature']) {
|
|
'bandwidth' => Metric::megabytes($estimate['usage'])->format(),
|
|
'storage' => Metric::megabytes($estimate['usage'])->format(),
|
|
};
|
|
|
|
// Normalize units
|
|
$amount = $estimate['amount'] / 1000;
|
|
|
|
return [
|
|
$estimate['feature'] => [
|
|
'feature' => $estimate['feature'],
|
|
'amount' => $amount,
|
|
'cost' => format_currency($amount, $currency),
|
|
'usage' => $usage,
|
|
]
|
|
];
|
|
});
|
|
}
|
|
}
|