amberovsky / currency
ISO-4217 Currency implementation
v0.3.2
2020-07-20 08:13 UTC
Requires
- php: ^7.4
- ext-json: *
- psr/simple-cache: ^1.0
Requires (Dev)
- phpspec/phpspec: ^6.2
- phpstan/phpstan: ^0.12
- vimeo/psalm: ^3.12
This package is auto-updated.
Last update: 2025-02-20 19:05:06 UTC
README
A simple ISO-4217 comprehensive Currency class with PSR-16 caching
How to use
Please provision Currency\Factory
with any PSR-16 implementation (for example, Symfony cache)
Symfony
Add this to the config\services.yaml
:
# Adapter from Symfony PSR-16 to PSR-6 amberovsky.money.currency.currencyFactory.cacheAdapter: class: Symfony\Component\Cache\Psr16Cache arguments: - '@cache.app' Amberovsky\Money\Currency\ISO4217: Amberovsky\Money\Currency\CurrencyFactory: public: true arguments: $ISO4217: '@Amberovsky\Money\Currency\ISO4217' $cache: '@amberovsky.money.currency.currencyFactory.cacheAdapter'
Examples
use Amberovsky\Money\Currency\CurrencyFactory; use Amberovsky\Money\Currency\ISO4217; $factory = new CurrencyFactory(new ISO4217(), new PSR16Cache()); $usd = $factory->fromNumericCode(ISO4217::NUMERIC_USD); // or $usd = $factory->fromAlphaCode(ISO4217::ALPHA_USD); // then $usd->getNumericCode(); // 809 $usd->getDescription(); // US Dollar $usd->getMinorUnits(); // 2 $usd->getAlphaCode(); // USD $usd->getSymbol(); // $ // also, these methods could be useful ISO4217::toNumericCode(string $alphaCode): int ISO4217::toAlphaCode(int $numericCode): string
Integration with Doctrine
Please use amberovsky/currency-doctrine if you need doctrine integration. It provides doctrine mapping type for Currency
How to contribute
Please fork this repo and create a PR. Make sure you run tests before submitting yout PR:
make phpstan make psalm make phpspec
License
Copyright (C) 2020 Anton Zagorskii, BSD-3-Clause license, See license file for details