WouterSioen / country-list
此包已被弃用,不再维护。作者建议使用 symfony/intl 包。
该包是 https://github.com/umpirsky/country-list 的包装器,可轻松获取特定语言的 国家列表或通过国家代码和语言获取特定国家。
1.0.1
2015-08-26 08:57 UTC
Requires
- php: >=5.3
- umpirsky/country-list: 1.*
This package is auto-updated.
Last update: 2019-08-07 07:31:13 UTC
README
弃用
您可以使用 symfony/intl 组件 https://symfony.ac.cn/doc/master/components/intl.html#country-names 做与此包相同的事情。
国家列表
该包是 https://github.com/umpirsky/country-list 的包装器,可轻松获取特定语言的 国家列表或通过国家代码和语言获取特定国家。
安装
composer.json
{ "require": { "woutersioen/country-list": "dev-master" } }
项目索引文件
// update this to the path to the "vendor/" directory, relative to this file require_once '../vendor/autoload.php';
使用
使用依赖注入容器
首先将 Sioen\Countries
类的实例添加到依赖注入容器中。
// fetch an array of countries in a language $languages = $this->getContainer()->get('countries')->getForLanguage('en'); // fetch one country in a language $language = $this->getContainer()->get('countries')->getSpecificForLanguage('be', 'en'); // returns 'Belgium'
大多数现代 PHP 框架都有依赖注入容器。这是首选方法,因为只有一个国家对象实例,并且数据将被缓存在该对象中。
PHP 5.4 (+)
use Sioen\Countries; // fetch an array of countries in a language $languages = (new Countries)->getForLanguage('en'); // fetch one country in a language $language = (new Countries)->getSpecificForLanguage('be', 'en'); // returns 'Belgium'
PHP 5.3
use Sioen\ContryList; $countries = new Countries(); // fetch an array of countries in a language $languages = $countries->getForLanguage('en'); // fetch one country in a language $language = $countries->getSpecificForLanguage('be', 'en'); // returns 'Belgium'