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管理项目的依赖项,只需将rebilly/country
添加到项目的composer.json
文件中即可。
类/对象
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许可证下开源的,并与软件一起分发。