tjbp / countries
用于ISO 3166国家数据的快速轻量级工具。
dev-master
2015-11-08 02:10 UTC
Requires (Dev)
- phpunit/phpunit: ^4.8
- riimu/kit-phpencoder: ^2.1
This package is auto-updated.
Last update: 2024-09-15 21:19:50 UTC
README
一个PHP库,提供快速轻量级工具来处理ISO 3166国家数据。
安装
在项目目录中运行以下命令以安装为依赖项
composer require tjbp/countries
用法
快速开始
use Tjbp\Currencies\Iso3166; Iso3166::get('GB')->name; // "United Kingdom of Great Britain and Northern Ireland (the)"
更详细地
use Tjbp\Countries\Iso3166; // Country object is returned with four properties Iso3166::get('GB')->name; // Iso3166::get('GB')->alpha2; // GB Iso3166::get('GB')->alpha3; // GBR Iso3166::get('GB')->numeric3; // 826 // Alternatively use an object $countries = new Iso3166; $countries->get('GB')->alpha2; // GB // Or get by specific identifiers if you prefer Iso3166::getByAlpha2('GB')->alpha2; // GB Iso3166::getByAlpha3('GBR')->alpha2; // GB Iso3166::getByNumeric3(826)->alpha2; // GB // Use the Iso3166::get() method to return a Country object $country = Iso3166::get('GB'); // Country has four properties $country->name; // "United Kingdom of Great Britain and Northern Ireland (the)" $country->alpha2; // "GB" $country->alpha3; // "GBR" $country->numeric3; // 826 // Alternatively instantiate Iso3166 $iso4217 = new Iso3166; $country = $iso4217->get('GBP'); // There are also specific identifiers if you prefer $country = Iso3166::getByAlpha2('GB'); $country = Iso3166::getByAlpha3('GBP'); $country = Iso3166::getByNumeric3(827);
此外,您还可以使用HasCountries特性,从对象内部访问Iso3166::get()方法
use Tjbp\Currencies\HasCountries; class Example { use HasCountries; public method example() { $this->countries('GB')->name; // "United Kingdom of Great Britain and Northern Ireland (the)" } }
构建
如果您想使用最新的ISO3166数据重新生成库,请运行bin/build
(尽管打包的源代码应该是最新的)。
贡献
对Iso3166类的更改是在src/templates/Iso3166.php
中进行的,因为src/Iso3166.php
将在构建新版本时被覆盖。