redcode / currency-rate-bundle
Symfony2 货币汇率包,允许通过cbr或ecb提供者进行货币转换和加载汇率
0.3.0
2022-05-10 09:17 UTC
Requires
- php: ^7.4
- doctrine/dbal: ^2
- doctrine/orm: ^2
- redcode/currency-rate: 0.2.*
- symfony/symfony: ^4.4
Requires (Dev)
This package is not auto-updated.
Last update: 2024-09-23 11:19:39 UTC
README
开始步骤
- 从Packagist安装模块到您的应用(packagist)
- 将包添加到内核
$bundles = array( ... new \RedCode\CurrencyRateBundle\RedCodeCurrencyRateBundle(), ... );
3. 创建货币和汇率类
/** * @ORM\Entity */ class Currency extends \RedCode\CurrencyRateBundle\Entity\Currency { /** * @var int * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; /** * @var string */ protected $code; }
/** * @ORM\Entity */ class CurrencyRate extends \RedCode\CurrencyRateBundle\Entity\CurrencyRate { /** * @var int * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; /** * @var \DateTime */ protected $date; /** * @var int */ protected $nominal; /** * @var float */ protected $rate; /** * @var \RedCode\Currency\ICurrency * @ORM\ManyToOne(targetEntity="Currency") * @ORM\JoinColumn(name="currency_id", referencedColumnName="id") */ protected $currency; /** * @var string */ protected $providerName; }
4. 在config.yml文件中添加部分
redcode_currency_rate: currency_rate_class: NameSpasePath\CurrencyRate currency_class: NameSpasePath\Currency
5. 只需运行命令
a. 创建基础货币
./app/console redcode:create:base:currencies
b. 创建加载汇率
./app/console redcode:currency:rate:load
6. 现在,您可以通过名称调用汇率转换器 - redcode.currency.rate.converter
$converter = $container->get('redcode.currency.rate.converter'); $convertedValue = $converter->convert('USD', 'EUR', $value);
贡献
欢迎pull requests。请参阅我们的CONTRIBUTING指南。