amberovsky / currency
ISO-4217 货币实现
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: 2024-09-20 18:08:25 UTC
README
一个简单的具有PSR-16缓存的ISO-4217综合货币类
如何使用
请用任何PSR-16实现(例如,Symfony 缓存)提供Currency\Factory
Symfony
将其添加到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'
示例
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
与Doctrine集成
如果您需要doctrine集成,请使用amberovsky/currency-doctrine。它为Currency
提供doctrine映射类型
如何贡献
请Fork此仓库并创建一个PR。在提交您的PR之前,请确保运行测试
make phpstan make psalm make phpspec
许可证
版权所有(C)2020 Anton Zagorskii,BSD-3-Clause许可证,详细信息请见许可证文件