PHP code example of honhat / convert-currency

1. Go to this page and download the library: Download honhat/convert-currency 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/ */

    

honhat / convert-currency example snippets


PHP
// config/services.php

$providers = [
    // ...
    Module\ConvertCurrency\Services\ExchangeRateProviders\FixerIoProvider::class,
];

PHP
use Module\ConvertCurrency\Services\CurrencyService;

class MyController
{
    private $currencyService;

    public function __construct(CurrencyService $currencyService)
    {
        $this->currencyService = $currencyService;
    }

    public function convertCurrency($amount, $fromCurrency, $toCurrency)
    {
        $convertedAmount = $this->currencyService->convert($amount, $fromCurrency, $toCurrency);

        return $convertedAmount;
    }
}

PHP
$convertedAmount = $this->currencyService->convert(100, 'USD', 'EUR');