PHP code example of savritsky / currency-rate-bundle

1. Go to this page and download the library: Download savritsky/currency-rate-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

savritsky / currency-rate-bundle example snippets


$bundles = array(
    ...
    new \RedCode\CurrencyRateBundle\RedCodeCurrencyRateBundle(),
    ...
);

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

$converter = $container->get('redcode.currency.rate.converter');
$convertedValue = $converter->convert('USD', 'EUR', $value);