@@ -46,6 +46,31 @@ final class CountryCatalogue
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Exact catalogue labels for reading legacy free-text country values.
|
||||
* Does not infer request origin, alter stored values or classify unmatched text.
|
||||
* Only labels belonging to one ISO country are included.
|
||||
*
|
||||
* @return list<string> Case-folded country code and catalogue labels.
|
||||
*/
|
||||
public function filterValues(string $code): array
|
||||
{
|
||||
$countries = $this->all();
|
||||
$owners = [];
|
||||
$selected = [];
|
||||
foreach ($countries as $country) {
|
||||
foreach (array_unique([$country['code'], $country['name'], $country['name_en']]) as $label) {
|
||||
$key = mb_strtolower(trim($label), 'UTF-8');
|
||||
$owners[$key][$country['code']] = true;
|
||||
if ($country['code'] === $code) {
|
||||
$selected[$key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_keys($selected), fn ($key) => count($owners[$key]) === 1));
|
||||
}
|
||||
|
||||
/** @return array{code:string|null,name:string} */
|
||||
public function describe(?string $code): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user