rebilly / country
country
v1.1.3
2023-07-11 12:53 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.3
README
国家项目
概览
该项目以值对象的形式管理国家信息。
安装
如果您使用Composer管理项目的依赖项,只需在项目的composer.json
文件中添加对rebilly/country
的依赖即可。
类/对象
Country
表示一个国家的值对象。
标识符为ISO 3166-1代码(字母和数字)。
使用的货币值为ISO 4217代码。
CountryRepository
该仓库包含一组Country对象,能够根据多个属性查找国家。
AdministrativeArea
表示省/州/地区/领地的值对象。由于各国命名不一致,我们使用“行政区域”这个术语。
标识符为ISO 3166-2代码(字母和数字)。
AdministrativeAreaRepository
该仓库包含一组AdministrativeArea对象,能够根据多个属性或国家查找行政区域。
用法
use Country\AdministrativeAreaRepository; use Country\CountryRepository; $countryRepository = new CountryRepository(); $administrativeAreaRepository = new AdministrativeAreaRepository($countryRepository); // get a list of all countries $countries = $countryRepository->findAll(); if ($countryRepository->hasWithIsoAlpha2('US')) { $usa = $countryRepository->findByIsoAlpha2('US'); echo $usa->getCommonName(); // United States echo $usa->getOfficialName(); // United States of America // get a list of all US states $administrativeAreaRepository->findByCountry($usa); if ($administrativeAreaRepository->hasWithNameAndCountry('New York', $usa)) { $newYork = $administrativeAreaRepository->findByNameAndCountry('New York', $usa); echo $newYork->getCode(); // NY } }
测试
phpunit
安全
如果您发现安全漏洞,请向security at rebilly dot com报告。
许可证
Country库是开源的,遵循MIT许可证,与软件一同分发。