You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-70Lines changed: 50 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,32 @@
7
7
8
8
> _Drop-in Symfony bundle for currency conversion. Multi-provider exchange rates with fallback, caching, and Symfony Cache integration. Maintained since 2014._
<strong>Sponsored by <a href="https://www.fastforex.io" target="_blank" rel="noopener">fastFOREX</a>.</strong> Real-time JSON API, 160+ currencies, 55+ years of history, 500+ cryptocurrencies. <strong>Free tier</strong>; paid plans from $18/month.
19
+
<a href="https://www.fastforex.io" target="_blank" rel="noopener"><strong>→ Get a free fastFOREX API key</strong></a>
20
+
</td>
21
+
</tr>
22
+
</table>
23
+
10
24
**Install the bundle, drop a `florianv_swap.yaml` in `config/packages/`, and the `florianv_swap.swap` service is ready to inject. No service container plumbing, no boilerplate.**
11
25
12
-
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. Used in real-world Symfony applications since 2014.
26
+
Symfony Swap is a drop-in package for **Symfony currency conversion**. Install it, configure providers in `config/packages/florianv_swap.yaml`, and pull 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.
13
27
14
28
## 💡 What is Symfony Swap?
15
29
16
-
-Symfony Swap is the Symfony integration of [Swap](https://github.com/florianv/swap), the PHP currency conversion library.
17
-
-It registers a `florianv_swap.swap` service in the container (`Swap\Swap` class).
30
+
-The Symfony integration of [Swap](https://github.com/florianv/swap), the PHP currency conversion library.
31
+
-Registers a `florianv_swap.swap` service in the container (`Swap\Swap` class).
18
32
- Configuration lives in `config/packages/florianv_swap.yaml`.
19
33
- Caching uses Symfony Cache (`array`, `apcu`, `filesystem`, or any PSR-16 service ID).
20
34
- Providers are tried in priority order (higher priority first).
21
35
22
-
## 🎯 When should you use Symfony Swap?
23
-
24
-
- Use Symfony Swap when you need exchange rates inside a Symfony application: localized prices, invoice totals, multi-currency reporting, historical FX data.
25
-
- You do not need to install [Swap](https://github.com/florianv/swap) separately. It is pulled in as a dependency, and Symfony Swap exposes it through Symfony's container and cache.
26
-
27
-
## 🧠 Why Symfony Swap and not raw Swap?
28
-
29
-
Using [Swap](https://github.com/florianv/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.
30
-
31
-
Symfony Swap does this for you:
32
-
33
-
-**Drop-in.** Add the bundle to `config/bundles.php` and you are set.
34
-
-**Symfony Cache integration.** Choose `array`, `apcu`, `filesystem`, or any PSR-16 service ID under `cache.type`.
35
-
-**Container service.**`florianv_swap.swap` is ready to inject from any controller, service, or command.
36
-
-**Configurable.**`config/packages/florianv_swap.yaml` exposes providers, options, and the cache.
37
-
-**Priority-ordered providers.** Each provider has a `priority`; the bundle sorts them (higher priority tried first).
38
-
39
-
If you are not on Symfony, use [Swap](https://github.com/florianv/swap) directly.
40
-
41
36
## 📦 Installation
42
37
43
38
Symfony Swap requires PHP 8.2 or newer and Symfony 6.4, 7, or 8.
@@ -56,22 +51,22 @@ return [
56
51
];
57
52
```
58
53
59
-
Skip to [Quickstart](#-quickstart).
60
-
61
-
---
62
-
63
-
_Optional: any PSR-18 HTTP client paired with a PSR-17 factory works. If your app already uses Guzzle, swap `symfony/http-client` for `php-http/guzzle7-adapter`. See the [documentation](Resources/doc/index.md) for alternatives._
64
-
65
54
## ⚡ Quickstart
66
55
67
-
Configure at least one provider in `config/packages/florianv_swap.yaml`. The European Central Bank works without an API key:
56
+
Configure providers in `config/packages/florianv_swap.yaml`. The recommended primary provider is **[fastFOREX](https://www.fastforex.io)** (the project's sponsor): a real-time JSON API behind a single `api_key`, [free tier available](https://www.fastforex.io).
68
57
69
58
```yaml
70
59
# config/packages/florianv_swap.yaml
71
60
florianv_swap:
61
+
cache:
62
+
ttl: 3600
63
+
type: filesystem
72
64
providers:
65
+
fastforex:
66
+
api_key: '%env(SWAP_FASTFOREX_KEY)%'
67
+
priority: 10# tried first
73
68
european_central_bank:
74
-
priority: 0
69
+
priority: 0# free fallback for EUR-base pairs
75
70
```
76
71
77
72
Inject the service:
@@ -95,7 +90,7 @@ final class CurrencyController
95
90
return [
96
91
'value'=> $rate->getValue(), // e.g. 1.0823
97
92
'date'=> $rate->getDate()->format('Y-m-d'), // e.g. 2026-04-29
Add commercial providers under `providers:` and they will be chained with the configured priority order:
106
+
Providers are tried in priority order (higher first). If a provider does not support the requested currency pair, it is skipped silently. If a provider throws an error, the next provider is tried. If every provider fails, a `ChainException` is thrown with all collected errors.
107
+
108
+
<details>
109
+
<summary>No API key? Start with the European Central Bank (free, EUR-base only).</summary>
112
110
113
111
```yaml
114
112
# config/packages/florianv_swap.yaml
115
113
florianv_swap:
116
-
cache:
117
-
ttl: 3600
118
-
type: filesystem
119
114
providers:
120
-
apilayer_fixer:
121
-
api_key: '%env(SWAP_FIXER_KEY)%'
122
-
priority: 10# tried first
123
-
open_exchange_rates:
124
-
app_id: '%env(SWAP_OER_APP_ID)%'
125
-
priority: 5# tried second
126
115
european_central_bank:
127
-
priority: 0# free fallback for EUR-base pairs
116
+
priority: 0
128
117
```
129
118
130
-
Providers are tried in priority order (higher first). If a provider does not support the requested currency pair, it is skipped silently. If a provider throws an error, the next provider is tried. If every provider fails, a `ChainException` is thrown with all collected errors.
119
+
The European Central Bank publishes EUR-base rates with daily granularity. For non-EUR base pairs, more frequent updates, or a wider currency list, switch to fastFOREX or another commercial provider.
120
+
</details>
131
121
132
122
## 💾 Caching
133
123
@@ -150,7 +140,18 @@ florianv_swap:
150
140
type: my_psr16_cache_service
151
141
```
152
142
153
-
Per-query overrides are documented in the [full documentation](Resources/doc/index.md#-caching).
143
+
Per-query overrides are documented in the [full documentation](Resources/doc/index.md#-per-query-options).
144
+
145
+
## 📊 Providers
146
+
147
+
Symfony Swap supports the 30 exchange rate providers from the underlying [Swap](https://github.com/florianv/swap) library. The recommended starting point for new projects is **[fastFOREX](https://www.fastforex.io)** (`fastforex`), the project's sponsor: live rates across 160+ fiat currencies and 500+ cryptocurrencies, with up to 55 years of history.
148
+
149
+
The full per-provider configuration reference (option name, optional flags, capabilities) is in the [documentation](Resources/doc/index.md#provider-configuration).
150
+
151
+
## 🎯 When should you use Symfony Swap?
152
+
153
+
- Use Symfony Swap when you need exchange rates inside a Symfony application: localized prices, invoice totals, multi-currency reporting, historical FX data.
154
+
- You do not need to install [Swap](https://github.com/florianv/swap) separately. It is pulled in as a dependency, and Symfony Swap exposes it through Symfony's container and cache.
154
155
155
156
## 🛠 Common use cases
156
157
@@ -164,37 +165,16 @@ Per-query overrides are documented in the [full documentation](Resources/doc/ind
164
165
165
166
The Swap ecosystem is a layered toolkit for currency conversion in PHP:
166
167
167
-
- **Swap.** The easy-to-use, high-level API for plain PHP.
168
-
- **Exchanger.** Lower-level, more granular alternative; direct access to provider implementations.
169
-
- **Laravel Swap.** Laravel application of Swap.
170
-
- **Symfony Swap.** Symfony integration of Swap (this package).
168
+
- [**Swap**](https://github.com/florianv/swap). The easy-to-use, high-level API for plain PHP.
169
+
- [**Exchanger**](https://github.com/florianv/exchanger). Lower-level, more granular alternative; direct access to provider implementations.
170
+
- [**Laravel Swap**](https://github.com/florianv/laravel-swap). Laravel application of Swap.
171
+
- [**Symfony Swap**](https://github.com/florianv/symfony-swap). Symfony integration of Swap (this package).
171
172
172
173
All four packages are MIT-licensed and require PHP 8.2 or newer.
173
174
174
175
## 📚 Documentation
175
176
176
-
The full documentation, with the per-provider configuration reference, custom service registration, cache types, and FAQ, is in [Resources/doc/index.md](Resources/doc/index.md). The full provider list with capabilities is in the [Swap README](https://github.com/florianv/swap#-providers).
- [**Laravel Swap**](https://github.com/florianv/laravel-swap): Laravel application of Swap.
185
-
- [**Symfony Swap**](https://github.com/florianv/symfony-swap): Symfony integration of Swap (this package).
186
-
187
-
## 🤝 Sponsorship
188
-
189
-
The Swap ecosystem is open to selected sponsorships from exchange rate API providers and financial infrastructure companies.
190
-
191
-
Sponsorship can include:
192
-
193
-
- Documentation visibility
194
-
- Integration examples
195
-
- Ecosystem-level visibility across Swap, Exchanger, Laravel Swap, and Symfony Swap
196
-
197
-
For inquiries, contact the maintainer via [GitHub](https://github.com/florianv).
177
+
The full documentation, with the per-provider configuration reference, custom service registration, cache types, and FAQ, is in [Resources/doc/index.md](Resources/doc/index.md).
Copy file name to clipboardExpand all lines: Resources/doc/index.md
+34-29Lines changed: 34 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,20 @@
1
1
# Documentation
2
2
3
-
## 💡 What is Symfony Swap?
4
-
5
-
- Symfony Swap is the Symfony integration of [Swap](https://github.com/florianv/swap), the PHP currency conversion library.
6
-
- It registers a `florianv_swap.swap` service in the container (`Swap\Swap` class).
7
-
- Configuration lives in `config/packages/florianv_swap.yaml`.
8
-
- Caching uses Symfony Cache (`array`, `apcu`, `filesystem`, or any PSR-16 service ID).
9
-
- Providers are tried in priority order (higher priority first).
10
-
11
-
For the wider ecosystem (Swap, Exchanger, Laravel Swap), see the [README](../../README.md).
12
-
13
-
## 🎯 When should you use Symfony Swap?
14
-
15
-
- Use Symfony Swap when you need exchange rates inside a Symfony application: localized prices, invoice totals, multi-currency reporting, historical FX data.
16
-
- You do not need to install [Swap](https://github.com/florianv/swap) separately. It is pulled in as a dependency, and Symfony Swap exposes it through Symfony's container and cache.
17
-
18
-
## 🧠 Why Symfony Swap and not raw Swap?
19
-
20
-
-**Drop-in.** Add the bundle to `config/bundles.php` and you are set.
21
-
-**Symfony Cache integration.** Choose `array`, `apcu`, `filesystem`, or any PSR-16 service ID under `cache.type`.
22
-
-**Container service.**`florianv_swap.swap` is ready to inject from any controller, service, or command.
23
-
-**Configurable.**`config/packages/florianv_swap.yaml` exposes providers, options, and the cache.
24
-
-**Priority-ordered providers.** Each provider has a `priority`; the bundle sorts them (higher priority tried first), unlike Swap and Laravel Swap, which use declaration order.
<strong>Sponsored by <a href="https://www.fastforex.io" target="_blank" rel="noopener">fastFOREX</a>.</strong> Real-time JSON API, 160+ currencies, 55+ years of history, 500+ cryptocurrencies. <strong>Free tier</strong>; paid plans from $18/month.
12
+
<a href="https://www.fastforex.io" target="_blank" rel="noopener"><strong>→ Get a free fastFOREX API key</strong></a>
13
+
</td>
14
+
</tr>
15
+
</table>
16
+
17
+
This is the technical reference for Symfony Swap. For the project overview and ecosystem (Swap, Exchanger, Laravel Swap), see the [README](../../README.md).
25
18
26
19
## Index
27
20
@@ -73,22 +66,27 @@ Create the configuration file at `config/packages/florianv_swap.yaml` (see [Conf
73
66
74
67
### Config tree
75
68
69
+
A typical config pins fastFOREX (the project's sponsor) as the primary provider, with the European Central Bank as a free fallback:
70
+
76
71
```yaml
77
72
# config/packages/florianv_swap.yaml
78
73
florianv_swap:
79
74
cache:
80
75
ttl: 3600
81
76
type: filesystem
82
77
providers:
78
+
fastforex:
79
+
api_key: '%env(SWAP_FASTFOREX_KEY)%'
80
+
priority: 10# tried first
83
81
european_central_bank:
84
-
priority: 0
82
+
priority: 0# free fallback for EUR-base pairs
85
83
```
86
84
87
85
At least one provider is required. Each provider accepts a `priority` integer (higher priority is tried first) and the provider-specific options listed below.
88
86
89
87
### Provider configuration
90
88
91
-
Public providers (central banks, national banks, `cryptonator`, `webservicex`) need only a `priority`:
89
+
Public providers (central banks, national banks) need only a `priority`:
92
90
93
91
```yaml
94
92
florianv_swap:
@@ -99,10 +97,12 @@ florianv_swap:
99
97
priority: 0
100
98
```
101
99
102
-
Commercial providers require an API key. The option name varies by provider:
100
+
Commercial providers require an API key. The option name varies by provider. The project's sponsor [fastFOREX](https://www.fastforex.io) (`fastforex`) is the recommended starting point.
@@ -118,11 +118,16 @@ Commercial providers require an API key. The option name varies by provider:
118
118
| `xchangeapi` | `api-key` | (note the hyphen) |
119
119
| `xignite` | `token` | |
120
120
121
-
Example:
121
+
> Note: `cryptonator`, `exchangeratehost` and `webservicex` are commercial upstream services but the current Exchanger wrapper does not enforce any option for them. They can be added with only a `priority`.
122
+
123
+
Example chaining fastFOREX as the primary provider with a couple of fallbacks:
$rate->getProviderName(); // string, the identifier that returned the rate
227
232
```
228
233
229
-
`getProviderName()` is useful when several providers are configured: the returned value is the identifier of the provider that actually answered, for example `european_central_bank`.
234
+
`getProviderName()` is useful when several providers are configured: the returned value is the identifier of the provider that actually answered, for example `fastforex`.
230
235
231
236
## 💾 Per-query options
232
237
@@ -354,7 +359,7 @@ Swap throws an `Exchanger\Exception\ChainException`. Calling `$exception->getExc
354
359
355
360
#### Can I use Symfony Swap without an API key?
356
361
357
-
Yes. The European Central Bank, the national banks, `cryptonator`, and `webservicex` do not require an API key. See the [Swap README's Providers table](https://github.com/florianv/swap#-providers) for the full list.
362
+
Yes. The European Central Bank and the national banks listed in the [Provider configuration](#provider-configuration) section require no key. A few commercial providers (`cryptonator`, `exchangeratehost`, `webservicex`) can also currently be used without one, since the Exchanger wrapper does not yet enforce an option for them.
#### Where is the full provider list with capabilities?
376
381
377
-
In the [Swap README's Providers table](https://github.com/florianv/swap#-providers). It lists every supported identifier with its base currency, quote currency, and historical support.
382
+
In the [Provider configuration](#provider-configuration) section above (option reference) and the [Swap README's Providers table](https://github.com/florianv/swap#-providers) (base currency, quote currency, historical support).
0 commit comments