定制 php-components/isocodes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-components/isocodes

Composer 安装命令:

composer require php-components/isocodes

包简介

PHP implementation of ISO codes package

README 文档

README

Build Status

PHP ISO codes based on the open source iso-codes project.

This project includes:

  • ISO-15924
  • ISO-3166-1
  • ISO-3166-2
  • ISO-3166-3
  • ISO-4217
  • ISO-639-2
  • ISO-639-3
  • ISO-639-5

...and the appropiate translations which are managed through the Translation Project.

Installation

The easiest and recommended way to install this library is through composer:

composer require php-components/isocodes

Adapters

Adapters are used in order to load the ISO data. Currently we support the following adapters:

  • Json
  • Pdo

However there are interfaces in place so you can write your own custom adapter. If you write your own adapter keep in mind it must inject the translator object into the objects.

The get($code) will determine which type of code has been supplied as an argument and will search for that type of code. The allowed types are the Alpha-2, Alpha-3, Alpha-4 and Numeric codes (If available in the requested ISO).

Some ISO files, such as ISO-639 have additional codes that match the pattern of Alpha-2, Alpha-3, Alpha-4 or Numeric codes. For those special cases an additional method is added to their adapters.

JSON Adapter

This adapter makes use of iso-codes JSON files to provide the ISO data. The data is stored as an array inside the adapter interfaces.

Usage Example:

use ISOCodes\ISO3166_1\Adapter\Json as ISO3166_1Adapter;

$adapter = new ISO3166_1Adapter();
// Get country with Alpha-2 code 'es' (Spain)
$country = $adapter->get('es');

if (null !== $country) {
    // Get the country name in Spanish ('es')
    echo $country->getName('es');
} else {
    echo 'Country not found!';
}

This shall return España

PDO Adapter

This adapter makes use of PDO to retrieve the ISO data from a database backend. By default it will use the included SQLite database but you may specify another PDO in the constructor of the adapter. The constuctor is defined as follows:

public function __construct(PDO $pdo = null)

$pdo will be you PDO object or you can leave it as null in order to load the default SQLite database.

Usage Example

use ISOCodes\ISO3166_1\Adapter\Pdo as ISO3166_1Adapter;

$adapter = new ISO3166_1Adapter();
// Get country with Alpha-2 code 'es' (Spain)
$country = $adapter->get('es');

if (null !== $country) {
    // Get the country name in Spanish ('es')
    echo $country->getName('es');
} else {
    echo 'Country not found!';
}

This shall return España

统计信息

  • 总下载量: 5.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: GPLv3
  • 更新时间: 2016-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固