1. Go to this page and download the library: Download steffenbrand/curr-curr 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/ */
steffenbrand / curr-curr example snippets
try {
$cc = new CurrCurr();
$exchangeRate = $cc->getExchangeRateByCurrency(Currency::USD);
$exchangeRate->getDate();
$exchangeRate->getCurrency();
$exchangeRate->getRate();
} catch (ExchangeRatesRequestFailedException $e) {
// webservice might not be present
} catch (ExchangeRatesMappingFailedException $e) {
// webservice might not deliver what we expect
} catch (CurrencyNotSupportedException $e) {
// requested currency might not be provided
}
try {
$cc = new CurrCurr();
$exchangeRates = $cc->getExchangeRates();
$exchangeRates[Currency::USD]->getDate();
$exchangeRates[Currency::USD]->getCurrency();
$exchangeRates[Currency::USD]->getRate();
foreach ($exchangeRates as $exchangeRate) {
$exchangeRate->getDate();
$exchangeRate->getCurrency();
$exchangeRate->getRate();
}
} catch (ExchangeRatesRequestFailedException $e) {
// webservice might not be present
} catch (ExchangeRatesMappingFailedException $e) {
// webservice might not deliver what we expect
}
$cc = new CurrCurr(
new EcbClient(
EcbClient::DEFAULT_EXCHANGE_RATES_URL,
new CacheConfig(
new OpCache(sys_get_temp_dir() . '/cache')
// Any PSR-16 compliant implementation
// This example uses odan/cache
)
)
);
new CacheConfig(
new OpCache(sys_get_temp_dir() . '/cache')
CacheConfig::CACHE_UNTIL_MIDNIGHT, // time to live in seconds
CacheConfig::DEFAULT_CACHE_KEY // key used for caching
);
$cc1 = new CurrCurr(new EcbClientMock(EcbClientMock::VALID_RESPONSE));
$cc2 = new CurrCurr(new EcbClientMock(EcbClientMock::USD_MISSING_RESPONSE));
$cc3 = new CurrCurr(new EcbClientMock(EcbClientMock::DATE_MISSING_RESPONSE));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.