waylandace/currency-rate-bundle

Symfony4 货币汇率包,允许通过 cbr 或 ecb 提供商进行货币转换和加载汇率

此包的规范存储库似乎已丢失,因此该包已被冻结。

安装: 183

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 5

类型:symfony-bundle

0.3.8 2020-01-17 15:23 UTC

This package is auto-updated.

Last update: 2024-02-18 00:15:54 UTC


README

启动步骤

  1. 将模块安装到您的应用中 从 Packagist
  2. 将包添加到内核
$bundles = array(
    ...
    new \RedCode\CurrencyRateBundle\RedCodeCurrencyRateBundle(),
    ...
);

3. 创建 Currency 和 CurrencyRate 类

/**
* @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);

贡献

欢迎提交拉取请求。请参阅我们的 CONTRIBUTING 指南。