Skip to content

CurrencyRepository

Manages currencies based on JSON definitions.

Properties

defaultLocale

The default locale.

protected string $defaultLocale

fallbackLocale

The fallback locale.

protected string $fallbackLocale

definitionPath

The path where per-locale definitions are stored.

protected string $definitionPath

definitions

Per-locale currency definitions.

protected array $definitions

availableLocales

The available locales.

protected array $availableLocales

Methods

__construct

Creates a CurrencyRepository instance.

public __construct(string $defaultLocale = 'en', string $fallbackLocale = 'en', string $definitionPath = null): mixed

Parameters:

Parameter Type Description
$defaultLocale string The default locale. Defaults to 'en'.
$fallbackLocale string The fallback locale. Defaults to 'en'.
$definitionPath string The path to the currency definitions.
Defaults to 'resources/currency'.

get

Gets a currency matching the provided currency code.

public get(mixed $currencyCode, mixed $locale = null): \CommerceGuys\Intl\Currency\Currency

Parameters:

Parameter Type Description
$currencyCode mixed The currency code.
$locale mixed The locale (i.e. fr-FR).

getAll

Gets all currencies.

public getAll(mixed $locale = null): \CommerceGuys\Intl\Currency\Currency[]

Parameters:

Parameter Type Description
$locale mixed The locale (i.e. fr-FR).

Return Value:

An array of currencies, keyed by currency code.


getList

Gets a list of currencies.

public getList(mixed $locale = null): string[]

Parameters:

Parameter Type Description
$locale mixed The locale (i.e. fr-FR).

Return Value:

An array of currency names, keyed by currency code.


loadDefinitions

Loads the currency definitions for the provided locale.

protected loadDefinitions(string $locale): array

Parameters:

Parameter Type Description
$locale string The desired locale.

getBaseDefinitions

Gets the base currency definitions.

protected getBaseDefinitions(): array

Contains data common to all locales: numeric code, fraction digits.

Return Value:

An array of definitions, keyed by currency code. Each definition is a numerically indexed array containing: - The numeric code. - The fraction digits.



Automatically generated on 2025-03-18