@@ -307,6 +307,52 @@ to catching the exception, you can also check if a given currency code is valid:
307
307
308
308
$isValidCurrency = Currencies::exists($currencyCode);
309
309
310
+ By default, the previous currency methods return all currencies, including
311
+ those that are no longer in use. Symfony provides several methods to filter
312
+ currencies so you can work only with those that are actually valid and in use
313
+ for a given country.
314
+
315
+ These methods use ICU metadata (``tender ``, ``from `` and ``to `` dates) to
316
+ determine whether a currency is `legal tender `_ and/or active at a specific
317
+ point in time::
318
+
319
+ use Symfony\Component\Intl\Currencies;
320
+
321
+ // get the list of today's legal and active currencies for a country
322
+ $codes = Currencies::forCountry('FR');
323
+ // ['EUR']
324
+
325
+ // include non-legal currencies too, and check them at a given date
326
+ $codesAll = Currencies::forCountry(
327
+ 'ES',
328
+ legalTender: null,
329
+ active: true,
330
+ date: new \DateTimeImmutable('1982-01-01')
331
+ );
332
+ // ['ESP', 'ESB']
333
+
334
+ // check if a currency is valid today for a country
335
+ $isOk = Currencies::isValidInCountry('CH', 'CHF');
336
+ // true
337
+
338
+ // check if a currency is valid in any country on a specific date
339
+ $isGlobal = Currencies::isValidInAnyCountry(
340
+ 'USD',
341
+ legalTender: true,
342
+ active: true,
343
+ date: new \DateTimeImmutable('2005-01-01')
344
+ );
345
+ // true
346
+
347
+ Note that some currencies (especially non-legal-tender ones) do not have validity
348
+ ranges defined. In such cases, a ``RuntimeException `` will be thrown. In addition,
349
+ an ``InvalidArgumentException `` will be thrown if the specified currency is invalid.
350
+
351
+ .. versionadded :: 7.4
352
+
353
+ The ``forCountry() ``, ``isValidInCountry() `` and ``isValidInAnyCountry() ``
354
+ methods were introduced in Symfony 7.4.
355
+
310
356
.. _component-intl-timezones :
311
357
312
358
Timezones
@@ -425,6 +471,7 @@ Learn more
425
471
.. _`ISO 3166-1 alpha-2` : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
426
472
.. _`ISO 3166-1 alpha-3` : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
427
473
.. _`ISO 3166-1 numeric` : https://en.wikipedia.org/wiki/ISO_3166-1_numeric
474
+ .. _`legal tender` : https://en.wikipedia.org/wiki/Legal_tender
428
475
.. _`UTC/GMT time offsets` : https://en.wikipedia.org/wiki/List_of_UTC_time_offsets
429
476
.. _`daylight saving time (DST)` : https://en.wikipedia.org/wiki/Daylight_saving_time
430
477
.. _`ISO 639-1 alpha-2` : https://en.wikipedia.org/wiki/ISO_639-1
0 commit comments