CountryAliasHelper
in package
Free-text country (a local-language name, "CZ", "cz", "Germany") → ISO 3166-1 alpha-2 code.
Pure (no I/O): the dictionary of country names comes from the caller (cms_system_country_texts, all languages,
read by CountryManager::findCountryNameDictionary()).
Resolution order — the first hit wins:
- exact alias with diacritics, case-insensitive (EXACT_ALIASES; the Czech abbreviation with a caron must not become Costa Rica),
- bare ISO code that exists in the dictionary ("CZ", "cz", "DE"),
- alias without diacritics (ALIASES),
- country name from the dictionary without diacritics — only when it names exactly one code.
IMPORTANT: never a silent default. Anything unrecognised (a typo, "1", a group label such as "other EU") is null and goes to the report.
Table of Contents
Constants
- ALIASES : array<string|int, mixed> = ['ceska republika' => 'CZ', 'cesko' => 'CZ', 'c...
- Aliases compared without diacritics, lower-cased, collapsed whitespace.
- EXACT_ALIASES : array<string|int, mixed> = ['čr' => 'CZ', 'sr' => null]
- Aliases where diacritics decide (the Czech abbreviation with a caron is not "CR", Costa Rica). Keys lower-cased.
Properties
Methods
- fromDictionary() : self
- normalize() : string
- Lower-case ASCII, separators collapsed to one space (a name with diacritics and a trailing dot becomes plain "ceska republika").
- resolve() : string|null
- ISO code of a free-text country, null when it cannot be recognised unambiguously.
- __construct() : mixed
- Private constructor: a helper with a data argument is not a DI service (`search` skips a class it cannot instantiate).
- known() : string|null
- An alias counts only when its code exists in the dictionary (a deactivated / missing country stays null).
Constants
ALIASES
Aliases compared without diacritics, lower-cased, collapsed whitespace.
private
array<string|int, mixed>
ALIASES
= ['ceska republika' => 'CZ', 'cesko' => 'CZ', 'czech republic' => 'CZ', 'czechia' => 'CZ', 'slovensko' => 'SK', 'slovenska republika' => 'SK', 'slovakia' => 'SK', 'slovak republic' => 'SK', 'nemecko' => 'DE', 'germany' => 'DE', 'deutschland' => 'DE', 'spolkova republika nemecko' => 'DE']
EXACT_ALIASES
Aliases where diacritics decide (the Czech abbreviation with a caron is not "CR", Costa Rica). Keys lower-cased.
private
array<string|int, mixed>
EXACT_ALIASES
= ['čr' => 'CZ', 'sr' => null]
Properties
$codes
private
array<string, true>
$codes
= []
ISO codes of the dictionary
$names
private
array<string, string|null>
$names
= []
normalized name → ISO code (null = ambiguous name)
Methods
fromDictionary()
public
static fromDictionary(array<string, array<int, string>> $namesByCode) : self
Parameters
- $namesByCode : array<string, array<int, string>>
-
ISO code → names in any language
Return values
selfnormalize()
Lower-case ASCII, separators collapsed to one space (a name with diacritics and a trailing dot becomes plain "ceska republika").
public
static normalize(string|null $value) : string
Parameters
- $value : string|null
Return values
stringresolve()
ISO code of a free-text country, null when it cannot be recognised unambiguously.
public
resolve(string|null $value) : string|null
Parameters
- $value : string|null
Return values
string|null__construct()
Private constructor: a helper with a data argument is not a DI service (`search` skips a class it cannot instantiate).
private
__construct(array<string, array<int, string>> $namesByCode) : mixed
Parameters
- $namesByCode : array<string, array<int, string>>
-
ISO code → names in any language
known()
An alias counts only when its code exists in the dictionary (a deactivated / missing country stays null).
private
known(string|null $code) : string|null
Parameters
- $code : string|null