@@ -311,18 +311,22 @@ to catching the exception, you can also check if a given currency code is valid:
311
311
312
312
$isValidCurrency = Currencies::exists($currencyCode);
313
313
314
- If the currencies need to be filtered, there are also helpers to query and
315
- validate currencies in relation to countries. These methods use ICU metadata
316
- (``tender ``, ``from `` and ``to `` dates) to determine whether a currency is
317
- `legal tender `_ and/or active at a given point in time::
314
+ By default, the previous currency methods return all currencies, including
315
+ those that are no longer in use. Symfony provides several methods to filter
316
+ currencies so you can work only with those that are actually valid and in use
317
+ for a given country.
318
+
319
+ These methods use ICU metadata (``tender ``, ``from `` and ``to `` dates) to
320
+ determine whether a currency is `legal tender `_ and/or active at a specific
321
+ point in time::
318
322
319
323
use Symfony\Component\Intl\Currencies;
320
324
321
- // Get the list of legal and active currencies for a country (defaults to "today")
325
+ // get the list of today's legal and active currencies for a country
322
326
$codes = Currencies::forCountry('FR');
323
327
// ['EUR']
324
328
325
- // Include non-legal currencies too, and check them at a given date
329
+ // include non-legal currencies too, and check them at a given date
326
330
$codesAll = Currencies::forCountry(
327
331
'ES',
328
332
legalTender: null,
@@ -331,11 +335,11 @@ validate currencies in relation to countries. These methods use ICU metadata
331
335
);
332
336
// ['ESP', 'ESB']
333
337
334
- // Validate a currency for a given country
338
+ // check if a currency is valid today for a country
335
339
$isOk = Currencies::isValidInCountry('CH', 'CHF');
336
340
// true
337
341
338
- // Check if a currency is valid in * any* country on a specific date
342
+ // check if a currency is valid in any country on a specific date
339
343
$isGlobal = Currencies::isValidInAnyCountry(
340
344
'USD',
341
345
legalTender: true,
@@ -344,9 +348,14 @@ validate currencies in relation to countries. These methods use ICU metadata
344
348
);
345
349
// true
346
350
347
- Note that some currencies (especially non-legal-tender ones) do not have validity ranges defined.
348
- In such cases, a ``RuntimeException `` will be thrown.
349
- In addition, an ``InvalidArgumentException `` will be thrown if the specified currency is invalid.
351
+ Note that some currencies (especially non-legal-tender ones) do not have validity
352
+ ranges defined. In such cases, a ``RuntimeException `` will be thrown. In addition,
353
+ an ``InvalidArgumentException `` will be thrown if the specified currency is invalid.
354
+
355
+ .. versionadded :: 7.4
356
+
357
+ The ``forCountry() ``, ``isValidInCountry() `` and ``isValidInAnyCountry() ``
358
+ methods were introduced in Symfony 7.4.
350
359
351
360
.. _component-intl-timezones :
352
361
0 commit comments