florianv/exchanger
PHP exchange-rate provider layer with 31 services behind one ExchangeRateService interface. Supports historical rates, PSR-16 caching, and chainable fallback across providers (commercial APIs, ECB, national banks, exchangerate.host) for fine-grained control.
ExchangeRateService interface. Aligns with Laravel’s dependency injection and service container patterns.Chain service enables graceful degradation—critical for financial applications where provider failures must not disrupt core functionality.Exchanger as a singleton binding (ExchangeRateService) with configurable providers (e.g., fastforex, european_central_bank).config/exchanger.php to define:
'providers' => [
'primary' => Exchanger\Service\FastForex::class,
'fallback' => [
Exchanger\Service\EuropeanCentralBank::class,
Exchanger\Service\Chain::class, // For nested fallbacks
],
],
'cache' => 'array', // PSR-16 cache (e.g., 'redis', 'file')
'api_keys' => [
'fastforex' => env('FASTFOREX_API_KEY'),
],
ExchangeRate facade for fluent access (e.g., ExchangeRate::convert(100, 'EUR', 'USD')).Http client (PSR-18) is auto-discoverable via php-http/discovery, reducing boilerplate.php-cache/simple-cache-bridge).fastforex) may introduce:
throttle or custom retry logic).webservicex) lack historical support; validate coverage for use cases.fastforex (paid) or a free alternative (e.g., european_central_bank)?config)?ChainException be caught globally (e.g., in Laravel’s App\Exceptions\Handler)?null, or use a default rate)?Mockery or Vcr for HTTP recordings)?Exchanger as a singleton with provider configurations.ExchangeRate::getRate('EUR/USD')).Http client or Guzzle (PSR-18 compliant).ExchangeRateUpdated) for observability.exchange_rates table for compliance/audit:
Schema::create('exchange_rates', function (Blueprint $table) {
$table->id();
$table->string('base_currency');
$table->string('target_currency');
$table->decimal('rate', 15, 6);
$table->dateTime('effective_at');
$table->string('provider')->nullable();
$table->timestamps();
});
FetchExchangeRates) to avoid blocking requests.florianv/exchanger and symfony/http-client (or Laravel’s Http).ExchangeRateService binding in AppServiceProvider:
$this->app->singleton(ExchangeRateService::class, function ($app) {
$service = new Chain([
new FastForex(null, null, ['api_key' => env('FASTFOREX_API_KEY')]),
new EuropeanCentralBank(),
]);
return new Exchanger($service, $app->make(SimpleCacheInterface::class));
});
ExchangeRate::getRate('EUR/USD')->getValue();
Exchanger calls.symfony/http-client (or Laravel’s Http) for PSR-18.php-cache/simple-cache-bridge to adapt Laravel’s cache to PSR-16.nyholm/psr7 (included via symfony/http-client).florianv/exchanger has no Laravel-specific dependencies.fastforex API key or alternative provider.Exchanger in the service container.ExchangeRateService (mock providers).florianv/exchanger for breaking changes (e.g., provider API deprecations).composer update and test fallbacks..env or a secrets manager (e.g., AWS Secrets Manager).App\Exceptions\Handler to catch ChainException and notify support.How can I help you explore Laravel packages today?