. */ declare(strict_types=1); namespace FireflyIII\Transformers; use FireflyIII\Models\TransactionCurrency; use League\Fractal\TransformerAbstract; use Symfony\Component\HttpFoundation\ParameterBag; /** * Class CurrencyTransformer */ class CurrencyTransformer extends TransformerAbstract { /** * List of resources possible to include * * @var array */ protected $availableIncludes = []; /** * List of resources to automatically include * * @var array */ protected $defaultIncludes = []; /** @var ParameterBag */ protected $parameters; /** * CurrencyTransformer constructor. * * @codeCoverageIgnore * * @param ParameterBag $parameters */ public function __construct(ParameterBag $parameters) { $this->parameters = $parameters; } /** * Transform the currency. * * @param TransactionCurrency $currency * * @return array */ public function transform(TransactionCurrency $currency): array { $isDefault = false; $defaultCurrency = $this->parameters->get('defaultCurrency'); if (null !== $defaultCurrency) { $isDefault = $defaultCurrency->id === $currency->id; } $data = [ 'id' => (int)$currency->id, 'updated_at' => $currency->updated_at->toAtomString(), 'created_at' => $currency->created_at->toAtomString(), 'name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol, 'decimal_places' => (int)$currency->decimal_places, 'default' => $isDefault, 'links' => [ [ 'rel' => 'self', 'uri' => '/currencies/' . $currency->id, ], ], ]; return $data; } }