omisai / php-countries
PHP 包提供国家数据
1.2.1
2024-06-08 19:29 UTC
Requires
- php: ^8.1
Requires (Dev)
- pestphp/pest: ^2.34
This package is auto-updated.
Last update: 2024-09-08 20:13:47 UTC
README
PHP 国家数据包
PHP 国家数据包提供了一种方便且面向对象的方式来处理国家数据。设计用于轻松将国家信息集成到任何PHP应用程序中。此包提供轻松访问国家名称、ISO 3166-1 alpha-2代码、ISO 3166-1 alpha-3代码、ISO 3166-1数字代码、FIPS代码、电话拨号、国家首都和洲代码。
功能
- 轻松检索国家名称和代码、首都和/或洲。
- 面向对象编程(OOP)方法,以更好地管理和集成数据。
- 轻量级且易于集成到任何PHP项目中。(8.1+)
- 目前支持英语、匈牙利语、德语、西班牙语、意大利语、法语和葡萄牙语。
- 未来支持多种地区设置,使其适用于国际应用程序。
安装
可以通过Composer轻松安装PHP国家数据包。
composer require omisai/php-countries
用法
安装包后,您可以开始处理任何国家数据。您可以直接使用国家模型,或通过集合类访问所有模型。
/** * Access through the Collection * * Consider using the Collection class, if you * plan to register it to a service container. * It eagerly loads all the countries. */ use Omisai\Countries\Collection; $collection = new Collection(); $countries = $collection->getCountries(); /** * Shorthand to use the default english locale */ $countries[4]->name; // "Finland" /** * Or using different locale */ $countries[4]->getName('fr'); // "Finlande" /** * Search for a specific country based on different criteria */ $collection->getCountryByAlpha2('FI'); // Omisai\Countries\Models\Finland $collection->getCountryByAlpha3('FIN'); // Omisai\Countries\Models\Finland $collection->getCountryByNumeric('246'); // Omisai\Countries\Models\Finland $collection->getCountryByFipCode('FI'); // Omisai\Countries\Models\Finland $collection->getCountryByDial('358'); // Omisai\Countries\Models\Finland $collection->getCountryByCapital('Helsinki'); // Omisai\Countries\Models\Finland $collection->getCountryByName('Finland'); // Omisai\Countries\Models\Finland $collection->getCountryByName('Finlande', "fr"); // Omisai\Countries\Models\Finland /** * Get only a part of data from the countries */ $collection->getCountriesAlpha2(); // ['country_name' => 'country_alpha2'] $collection->getCountriesAlpha3(); // ['country_name' => 'country_alpha3'] $collection->getCountriesNumeric(); // ['country_name' => 'country_numeric'] $collection->getCountriesFipCode(); // ['country_name' => 'country_fipCode'] $collection->getCountriesDial(); // ['country_name' => 'country_dial'] $collection->getCountriesAlpha2('fr'); // ['fr:country_name' => 'country_alpha2'] -> ['Finlande' => 'FI'] $collection->getCountriesByContinent('EU'); // [Omisai\Countries\Models\Finland, Omisai\Countries\Models\Hungary, ...] /** * Use any country directly */ use Omisai\Countries\Models\Finland; $europe = new Finland(); $europe->alpha2; // "FI" $europe->alpha3; // "FIN" $europe->numeric; // "246" $europe->fipCode; // "FI" $europe->dial; // "358" $europe->capital; // "Helsinki" $europe->continent; // "EU" $europe->hu; // "Finnország" $europe->name; // "Finland" $europe->getName('it'); // "Finlandia"
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
测试
./vendor/bin/pest # or composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件security@omisai.com联系,而不是使用问题跟踪器。
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。