1. Go to this page and download the library: Download lemonade/component_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/ */
use DateTimeImmutable;
use Lemonade\Currency\CurrencyRate;
// Get the ratio of a foreign currency against the local currency.
$eurRatio = CurrencyRate::getRatio(currency: 'EUR');
// Get the value of a foreign currency against CZK.
$usdValue = CurrencyRate::getValue(currency: 'USD');
// Resolve a rate for a specific date.
$eurRatioForDate = CurrencyRate::getRatio(
currency: 'EUR',
date: new DateTimeImmutable('2023-12-01')
);
$usdValueForDate = CurrencyRate::getValue(
currency: 'USD',
date: new DateTimeImmutable('2023-12-01')
);
use DateTimeImmutable;
use Lemonade\Currency\CurrencyRate;
use Lemonade\Currency\Domain\CurrencyCode;
$eurValue = CurrencyRate::getValue(CurrencyCode::EUR);
$usdValueForDate = CurrencyRate::getValue(
currency: CurrencyCode::USD,
date: new DateTimeImmutable('2023-12-01')
);
use DateTimeImmutable;
use Lemonade\Currency\CurrencyMarket;
use Lemonade\Currency\Domain\CurrencyCode;
$market = new CurrencyMarket(new DateTimeImmutable('2023-12-01'));
$eurRatio = $market->getRatio(CurrencyCode::EUR);
$usdValue = $market->getValue(CurrencyCode::USD);
use Lemonade\Currency\CurrencyList;
use Lemonade\Currency\Domain\CurrencyCode;
$currencies = CurrencyList::getCurrencies();
$symbols = CurrencyList::getCurrencySymbolList();
$eurSymbol = CurrencyList::getCurrencySymbol(CurrencyCode::EUR);
$eurName = CurrencyList::getCurrencyLanguageName(CurrencyCode::EUR);
use Lemonade\Currency\Application\CurrencyRateService;
use Lemonade\Currency\Domain\DefaultCurrencyRates;
use Lemonade\Currency\Infrastructure\Cache\FileExchangeRateCache;
use Lemonade\Currency\Infrastructure\Clock\SystemClock;
use Lemonade\Currency\Infrastructure\Cnb\CnbExchangeRateSource;
use Lemonade\Currency\Infrastructure\Cnb\CnbRateParser;
$service = new CurrencyRateService(
cache: new FileExchangeRateCache(__DIR__ . '/var/cache/cnb'),
source: new CnbExchangeRateSource(),
parser: new CnbRateParser(),
defaults: new DefaultCurrencyRates(),
clock: new SystemClock(),
);
$value = $service->getValue('EUR');
use Lemonade\Currency\Port\ExchangeRateSource;
final class CustomExchangeRateSource implements ExchangeRateSource
{
public function fetchYear(int $year): string
{
// Return raw yearly exchange-rate data in the format expected by the configured parser.
return 'Datum|1 EUR' . PHP_EOL . '2.1.2024|24,725';
}
public function getUrl(int $year): string
{
return 'custom://currency-rates/' . $year;
}
}