benjaminmal/exchangeratehost-bundle
Unofficial Symfony bundle for the free exchangerate.host API. PSR-7/17/18 compatible so you can choose your HTTP client and message factories, with built-in Symfony Cache support for faster, fewer requests. PHP 8.1+ and Symfony 6.2+.
Bundle to Laravel’s ServiceProvider).ExchangeRateHostClientInterface in a Laravel facade for cleaner syntax (e.g., ExchangeRate::convert()).Guzzle) and PSR-17 factories (symfony/http-foundation) can replace Symfony’s dependencies with minimal effort.symfony/http-foundation) eliminates dependency conflicts.exchangerate_host.yaml config can be mirrored in Laravel’s config/exchangerate_host.php with minimal adaptation.CacheManager for pool-specific configurations.Bundle system and DependencyInjection. A Laravel TPM would need to:
Bundle with a Laravel ServiceProvider.ExchangeRateHostClientInterface) to implementations in the container.exchangeratehost.cache) may conflict with Laravel’s naming conventions. A TPM could use Laravel’s Cache::store() or rename pools in the config.throw_if in service methods)..env) or injected via a config file?retry helper).spatie/laravel-currency).laravel-exchangeratehost) for easier updates?// config/app.php
'http' => [
'client' => GuzzleHttp\Client::class,
],
symfony/http-foundation (already in Laravel) for request/URI factories.// config/cache.php
'stores' => [
'exchangeratehost' => [
'driver' => 'redis',
'connection' => 'cache',
],
],
ServiceProvider to:
ExchangeRateHostClientInterface to the bundle’s implementation.config/exchangerate_host.php).// app/Providers/ExchangeRateHostServiceProvider.php
public function register()
{
$this->app->bind(
ExchangeRateHostClientInterface::class,
ExchangeRateHostClient::class
);
$this->mergeConfigFrom(__DIR__.'/../../config/exchangerate_host.php', 'exchangerate_host');
}
composer require benjaminmal/exchangeratehost-bundle nyholm/psr7 symfony/http-client
exchangerate_host.yaml to Laravel’s config/exchangerate_host.php:
return [
'cache' => [
'enabled' => true,
'pools' => [
'latest_rates' => 'exchangeratehost',
// ...
],
],
];
config/cache.php (see above).ServiceProvider in config/app.php.// app/Facades/ExchangeRate.php
public static function convert(string $from, string $to, float $amount): float
{
return app(ExchangeRateHostClientInterface::class)->convertCurrency($from, $to, $amount);
}
ExchangeRateHostClientInterface in unit tests.php artisan cache:clear) simplify cache maintenance.// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('cache:clear exchangeratehost')->dailyAt('00:06');
}
How can I help you explore Laravel packages today?