Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Swap Bundle

Swap Bundle Laravel Package

florianv/swap-bundle

Symfony bundle for the Swap currency exchange library. It integrates exchange-rate providers into Symfony, enabling currency conversion, rate lookup, and configurable provider and caching setup through a simple service-oriented API.

View on GitHub
Deep Wiki
Context7

Drop-in Symfony bundle for currency conversion: configurable services, multi-provider exchange rates with fallback and caching.

Frequently asked questions about Swap Bundle
Can I use florianv/swap-bundle in a Laravel application?
No. SwapBundle is a Symfony bundle built on the bundle-extension lifecycle: its FlorianvSwapExtension::load() takes a Symfony ContainerBuilder, which Laravel does not expose, so the package will not boot. The useful part sits one layer down in florianv/swap, which is framework-agnostic and installs cleanly alongside Laravel. Read the bundle as a reference implementation, then reproduce roughly 50 to 100 lines of service-provider code around the library.
What PHP and Symfony versions does swap-bundle 6.0 require?
Version 6.0.0 requires PHP ^8.2 and Symfony ^6.4, ^7.0 or ^8.0, dropping support for PHP 7.x and Symfony 3.x through 5.x. The PHP floor matches Laravel 11 and 12 but rules out Laravel 9 or Laravel 10 hosts pinned to PHP 8.1. If you intend to install the bundle anywhere, verify the Symfony floor against older Laravel 10 patch releases, which ship Symfony 6.2 or 6.3 components. Also check whether florianv/swap itself carries the same floor, since that is the package a Laravel application actually installs.
How do I install and configure swap-bundle in Symfony?
Require the package with Composer, then declare your providers, API keys and options under config/packages/swap.yaml. The bundle's extension reads that configuration and registers the services it needs, so you never wire providers manually. After that you can autowire the swap service into any controller, service or Twig template.
How do I convert currencies in a Symfony controller or Twig template?
Inject the swap service into your controller or service constructor and call the library's conversion methods with a currency pair, such as EUR to USD. The bundle also ships a Twig extension so converted amounts can be rendered directly in templates. Because the service is autowired, the same configured instance is shared across controllers, services and views.
What is the best way to use Swap for currency conversion in Laravel?
Install florianv/swap directly with Composer and bind it as a singleton in a service provider, modelling a config/swap.php file on the bundle's YAML. Configure providers, fallback order and credentials there, and read them through config() when constructing the Swap instance. Wrap the library behind your own interface so mocking in tests stays cheap and a future library swap does not touch application code.
Which exchange rate providers does swap-bundle support, and where do API keys go?
The bundle supports the exchange-rate providers shipped by the underlying florianv/swap library, and you list and prioritise them in YAML. Each entry takes a provider name, its credentials and any provider-specific options, with the API key supplied as configuration rather than hard-coded. Check the florianv/swap documentation for the current provider list and option names, and keep secrets in environment variables referenced from the YAML.
How does caching work with swap-bundle, and how do I do the same in Laravel?
In Symfony the bundle relies on Symfony Cache to store fetched rates, so you configure a cache pool through the bundle configuration. In Laravel you substitute an adapter over Illuminate\Contracts\Cache\Repository implementing PSR-16 and pass it to florianv/swap, which accepts PSR-6 and PSR-16 caches. Choose lifetimes deliberately: exchange-rate endpoints usually update hourly or daily, and stale rates are a business risk rather than just a performance trade-off.
Is florianv/swap-bundle actively maintained and safe for production?
It is MIT licensed, and 6.0.0 shows real engineering hygiene: Psalm level 1 static analysis gated in CI, a backward-compatibility check workflow, and a test matrix covering PHP 8.2 through 8.5. Adoption is thin, with roughly 63 stars and no dependents, so there is little crowd-sourced bug surface and almost no tutorial coverage. Bus factor is closer to 1.5 after recent contributors joined, so budget time for reading the source rather than expecting abandonment. Provider risk still dominates package risk, because exchange-rate APIs deprecate endpoints and change response formats independently of this code.
How do I test currency conversion without calling a live exchange rate API?
Depend on an interface around the Swap service and bind a fake or stub in your test container so controllers and services are tested against fixed rates. In Symfony you can override the swap service in the test container; in Laravel bind a test double in the service provider or per test. Keep a small separate integration test against a real provider to catch API changes, but never let it gate your unit suite. The bundle ships no testing helpers, so the mocking strategy is yours to own.
What are the alternatives to swap-bundle for currency conversion in Laravel or Symfony?
The closest option is using florianv/swap directly, which is what a Laravel application should do and which removes the bundle dependency entirely. For Symfony teams the bundle is a genuine drop-in and worth its configuration surface. If you need only a handful of rates, one cached HTTP client call to a single provider may be simpler than any abstraction. For arithmetic-heavy money handling, pair a rate source with a dedicated money library instead of relying on floats.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource