Czech National Bank#
This service retrieves the data from the Czech National Bank.
Installation#
Install the service:
composer require peso/cnb-service
Install the service with all recommended dependencies:
composer require peso/cnb-service php-http/discovery guzzlehttp/guzzle symfony/cache
Usage#
Example:
<?php
use Peso\Peso\CurrencyConverter;
use Peso\Services\CzechNationalBankService;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
require __DIR__ . '/../vendor/autoload.php';
$cache = new Psr16Cache(new FilesystemAdapter(directory: __DIR__ . '/cache'));
$service = new CzechNationalBankService($cache);
$converter = new CurrencyConverter($service);
// 310812.50 as of 2025-06-23
echo $converter->convert('12500', 'EUR', 'CZK', 2), PHP_EOL;
// reversible (wraps service with ReversibleService)
$service = CzechNationalBankService::reversible($cache);
$converter = new CurrencyConverter($service);
// 502.71 as of 2025-06-23
echo $converter->convert('12500', 'CZK', 'EUR', 2), PHP_EOL;
Warning
Reversible Factory emits non-precise services that can only be used in informational purposes.