mibo/countries

ISO 3166-1 国家代码的PHP库

2.0.0 2024-08-08 15:26 UTC

This package is auto-updated.

Last update: 2024-09-08 15:56:38 UTC


README

codecov

mibo/countries

该库提供了一个简单的接口,用于国家实体和国家提供者,可以通过ISO 3166-1 alpha-2代码、alpha-3代码或数字代码检索国家。提供者还可以通过国家名称检索国家。
如果提供者找不到国家,则返回null。

国家实体包含其名称、ISO 3166-1 alpha-2代码、alpha-3代码、数字代码以及该国家的货币(对象)。

可用的国家列表可以通过提供者进行更改,因为库(ISO)提供者使用来自'league/iso3166'库的提供者,该库提供相同的数据,但以数组形式。

$provider = new \MiBo\Countries\ISO\CountryProvider(
    new \League\ISO3166\ISO3166($myCountryList ?? []),
    new \MiBo\Currencies\ISO\ISOCurrencyProvider(
        new \MiBo\Currencies\ISO\ISOArrayListLoader(),
        new \Psr\Log\NullLogger()
    )
)

$country = $provider->getByAlpha2('SK');

echo $country->getName(); // Slovakia
echo $country->getAlpha2(); // SK
echo $country->getAlpha3(); // SVK
echo $country->getNumericalCode(); // 703
echo $country->getCurrencies()[0]; // EUR