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
docs: restructure doc/readme.md to align with the README
Add three orientation sections at the top of the doc so a developer or
search engine landing on doc/readme.md directly gets the same value
proposition as the README:
- 'What is Swap?' (factual, ~5 lines)
- 'When should you use Swap?' (factual, ~3 lines)
- 'Why not call an exchange rate API directly?' (mirrors the README
verbatim so the canonical phrasing is consistent across both surfaces)
Drop the 'About this documentation' meta section; its orientation role
is taken over by the three sections above.
Compact 'Per-query options' from three sub-headings (cache_ttl, cache,
cache_key_prefix) into a single options table plus one example block.
Same information, denser and easier to scan.
Trim the prose around the HTTP request caching example.
Add one FAQ entry: 'How does Swap relate to Exchanger?' that points to
the README's 'Which package should I use?' section, so the doc covers
the ecosystem map without duplicating it.
Update the index to reflect the new section order and the emoji-prefixed
anchors.
Net length: roughly the same as before; structure is clearer, the doc
stands on its own for a discovery-stage reader, and vocabulary is
aligned with the README ('currency conversion library', 'exchange rate
provider', 'fallback chain', 'caching').
Copy file name to clipboardExpand all lines: doc/readme.md
+60-51Lines changed: 60 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,55 @@
1
1
# Documentation
2
2
3
-
## 📘 About this documentation
3
+
## 💡 What is Swap?
4
4
5
-
This documentation covers the practical use of Swap, the PHP currency conversion library: configuration, caching, provider configuration, and how to write your own provider. For an overview of the library and the wider ecosystem (Exchanger, Laravel Swap, Symfony Swap), see the [README](../README.md).
5
+
- Swap is a PHP library for currency conversion and exchange rate retrieval.
6
+
- It exposes a wide range of exchange rate providers behind a common interface.
7
+
- It caches results via PSR-16 SimpleCache.
8
+
- It supports historical rates.
9
+
- It supports a fallback chain. When a provider errors, the next provider in the chain is tried.
10
+
11
+
For the wider ecosystem (Exchanger, Laravel Swap, Symfony Swap), see the [README](../README.md).
12
+
13
+
## 🎯 When should you use Swap?
14
+
15
+
- Use Swap when you need to retrieve exchange rates in a PHP application: currency conversion workflows, multi-currency pricing, invoice totals, reconciliation, or historical FX data.
16
+
- Use the lower-level [Exchanger](https://github.com/florianv/exchanger) library when Swap's defaults are too opinionated and you want finer control over chain composition, caching, or HTTP plumbing.
17
+
18
+
## 🧠 Why not call an exchange rate API directly?
19
+
20
+
You can integrate a single exchange rate API directly in your application.
21
+
22
+
Swap is useful when you need more than a single provider:
23
+
24
+
-**Provider abstraction** — switch providers without rewriting your code
25
+
-**Fallback support** — if one provider fails, another can be used automatically
26
+
-**Unified interface** — all providers share the same API
27
+
-**Caching** — reduce API calls and improve performance
28
+
-**Flexibility** — combine public and commercial providers
29
+
30
+
For simple use cases, calling a single API may be enough.
31
+
32
+
Swap becomes valuable when you need reliability, flexibility, or long-term maintainability.
*[Creating a custom service](#-creating-a-custom-service)
23
50
*[Standard service](#standard-service)
24
51
*[Historical service](#historical-service)
25
-
*[FAQ](#faq)
52
+
*[FAQ](#-faq)
26
53
27
54
## 📦 Installation
28
55
@@ -56,7 +83,7 @@ $swap = (new Builder())
56
83
->build();
57
84
```
58
85
59
-
`add()` registers a provider by its identifier (the string passed to `Builder::add()`, for example `european_central_bank`). The full list of identifiers is in the README's [Providers table](../README.md#providers).
86
+
`add()` registers a provider by its identifier (the string passed to `Builder::add()`, for example `european_central_bank`). The full list of identifiers is in the README's [Providers table](../README.md#-providers).
60
87
61
88
### Adding multiple providers
62
89
@@ -72,7 +99,7 @@ $swap = (new Builder())
72
99
->build();
73
100
```
74
101
75
-
Identifiers and the configuration keys each one accepts are documented in the [Provider configuration](#provider-configuration) section.
102
+
Identifiers and the configuration keys each one accepts are documented in the [Provider configuration](#-provider-configuration) section.
76
103
77
104
### How the fallback chain works
78
105
@@ -159,49 +186,30 @@ $cache = new SimpleCacheBridge(new PredisCachePool($client));
159
186
160
187
### Per-query options
161
188
162
-
Cache behavior can be overridden per call.
163
-
164
-
#### `cache_ttl`
165
-
166
-
Cache TTL in seconds. Default: `null` (cache entries do not expire).
Override the cache key prefix for a single query. Default: empty string.
185
-
186
-
PSR-6 limits cache keys to 64 characters. The internal hash of the query takes 40 characters, so the prefix must not exceed 24 characters. PSR-6 also does not allow the characters `{}()/\@:` in keys; Swap replaces them with `-`.
Some providers return all rates for a given base currency in a single response. If you fetch several pairs sharing the same base (for example `EUR/USD` and then `EUR/GBP`), caching the underlying HTTP response avoids hitting the provider twice.
196
-
197
-
Install the PHP HTTP cache plugin and a PSR-6 cache adapter:
207
+
Some providers return all rates for a given base currency in a single response. If you fetch several pairs sharing the same base (for example `EUR/USD` and then `EUR/GBP`), caching the underlying HTTP response avoids hitting the provider twice. Decorate your HTTP client with the PHP HTTP cache plugin and pass it to `Builder::useHttpClient()`:
The full provider list with capabilities (base currency, quote currency, historical support) is in the README's [Providers table](../README.md#providers).
288
+
The full provider list with capabilities (base currency, quote currency, historical support) is in the README's [Providers table](../README.md#-providers).
284
289
285
290
## 🧩 Creating a custom service
286
291
@@ -370,7 +375,11 @@ Swap throws an `Exchanger\Exception\ChainException`. Calling `$exception->getExc
370
375
371
376
#### Can I use Swap without an API key?
372
377
373
-
Yes. The European Central Bank, the national banks, `cryptonator`, `exchangeratehost`, and `webservicex` do not require an API key. See the [Providers table](../README.md#providers) for the full list.
378
+
Yes. The European Central Bank, the national banks, `cryptonator`, `exchangeratehost`, and `webservicex` do not require an API key. See the [Providers table](../README.md#-providers) for the full list.
379
+
380
+
#### How does Swap relate to Exchanger?
381
+
382
+
Swap is the high-level, easy-to-use API. Exchanger is the lower-level provider layer Swap is built on. Reach for Exchanger directly only when you need finer control over chain composition, caching, or HTTP plumbing. See the README's [Which package should I use?](../README.md#-which-package-should-i-use) section.
374
383
375
384
#### How do I cache rates?
376
385
@@ -382,8 +391,8 @@ Pass `['cache' => false]` as the options argument: `$swap->latest('EUR/USD', ['c
382
391
383
392
#### How do I add my own provider?
384
393
385
-
Implement `Exchanger\Contract\ExchangeRateService` (or extend `HttpService` / `Service`), register it with `Swap\Service\Registry::register()`, then call `Builder::add()` with your identifier. See [Creating a custom service](#creating-a-custom-service).
394
+
Implement `Exchanger\Contract\ExchangeRateService` (or extend `HttpService` / `Service`), register it with `Swap\Service\Registry::register()`, then call `Builder::add()` with your identifier. See [Creating a custom service](#-creating-a-custom-service).
386
395
387
396
#### Where is the full provider list with capabilities?
388
397
389
-
In the README's [Providers table](../README.md#providers). It lists every supported identifier with its base currency, quote currency, and historical support.
398
+
In the README's [Providers table](../README.md#-providers). It lists every supported identifier with its base currency, quote currency, and historical support.
0 commit comments