Skip to the content.

Drop-in Symfony bundle for currency conversion. Install, register, drop a florianv_swap.yaml in config/packages/, and inject florianv_swap.swap. No service container plumbing, no boilerplate.

Wiring an exchange rate library into Symfony usually means container plumbing, cache bridging, and HTTP client management. Symfony Swap does this for you.

Used in production Symfony applications since 2014.

Symfony Swap is a drop-in package for Symfony currency conversion. Install it, configure providers in config/packages/florianv_swap.yaml, and pull Symfony exchange rates from multiple providers in one call. The bundle integrates with Symfony Cache out of the box and supports Symfony 6.4 / 7 / 8.

What is Symfony Swap?

When should you use Symfony Swap?

Why Symfony Swap and not raw Swap?

Using Swap directly inside a Symfony app means three pieces of plumbing on every project: registering the builder and the Swap service yourself, wiring Symfony Cache to the PSR-16 contract, and configuring providers in PHP rather than in the container. Doable, but boilerplate every project pays for.

Symfony Swap does this for you:

Quickstart

Symfony Swap requires PHP 8.2 or newer and Symfony 6.4, 7, or 8.

Install via Composer:

composer require florianv/swap-bundle symfony/http-client nyholm/psr7

Register the bundle in config/bundles.php:

// config/bundles.php
return [
    // ...
    Florianv\SwapBundle\FlorianvSwapBundle::class => ['all' => true],
];

Configure at least one provider in config/packages/florianv_swap.yaml. The European Central Bank works without an API key:

# config/packages/florianv_swap.yaml
florianv_swap:
    providers:
        european_central_bank:
            priority: 0

Inject the service:

use Swap\Swap;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

final class CurrencyController
{
    public function __construct(
        #[Autowire(service: 'florianv_swap.swap')]
        private readonly Swap $swap,
    ) {}

    public function rate(): array
    {
        // EUR → USD exchange rate
        $rate = $this->swap->latest('EUR/USD');

        return [
            'value'    => $rate->getValue(),                 // e.g. 1.0823
            'date'     => $rate->getDate()->format('Y-m-d'), // e.g. 2026-04-29
            'provider' => $rate->getProviderName(),          // 'european_central_bank'
        ];
    }
}

Add commercial providers under providers: and they will be chained in priority order.

View on GitHub

Source code, full documentation, providers list, and issue tracker:

→ View on GitHub

Documentation

The full documentation, with the per-provider configuration reference, custom service registration, cache types, and FAQ, is in Resources/doc/index.md on the GitHub repository.


Symfony Swap is open to selected partnerships with exchange rate providers.