PHP code example of rapidwebltd / simple-currency-rates
1. Go to this page and download the library: Download rapidwebltd/simple-currency-rates 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/ */
rapidwebltd / simple-currency-rates example snippets
use RapidWeb\SimpleCurrencyRates\SimpleCurrencyRates;
$rates = (new SimpleCurrencyRates())->get('GBP');
$rates = new SimpleCurrencyRates($psr16Cache);
// Or replace it later.
$rates->setCache($psr6CachePool);
use RapidWeb\SimpleCurrencyRates\Cache\FilesystemCache;
$rates = new SimpleCurrencyRates(
new FilesystemCache('/var/cache/my-application/currency-rates')
);
use RapidWeb\SimpleCurrencyRates\Contracts\RateSourceInterface;
class CompanyRateSource implements RateSourceInterface
{
public function getRates($base)
{
return [
'EUR' => 1.16,
'USD' => 1.35,
];
}
public function getCacheTtl()
{
return 300;
}
}
$rates = new SimpleCurrencyRates($cache, [
new CompanyRateSource(),
]);
$rates
->setSources([new CompanyRateSource()])
->addSource($anotherSource);
use RapidWeb\SimpleCurrencyRates\Sources\FrankfurterRateSource;
$source = new FrankfurterRateSource(function ($url) use ($httpClient) {
return $httpClient->get($url)->getBody()->getContents();
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.