tiny-blocks/country 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tiny-blocks/country

最新稳定版本:2.3.1

Composer 安装命令:

composer require tiny-blocks/country

包简介

Value Object representing a country using ISO-3166 specifications.

README 文档

README

License

Overview

Value Object representing a country using ISO-3166 specifications.

Installation

composer require tiny-blocks/country

How to use

The library exposes country codes according to ISO-3166 specifications. Also, it is possible to create a representation of a country that groups the codes and its name.

Alpha2Code

A two-letter code that represents a country name, recommended as the general purpose code.

$alpha2Code = Alpha2Code::UNITED_STATES_OF_AMERICA; $alpha2Code->name; # UNITED_STATES_OF_AMERICA $alpha2Code->value; # US $alpha2Code->toAlpha3()->value; # USA

Alpha3Code

A three-letter code that represents a country name, which is usually more closely related to the country name.

$alpha3Code = Alpha3Code::UNITED_STATES_OF_AMERICA; $alpha3Code->name; # UNITED_STATES_OF_AMERICA $alpha3Code->value; # USA $alpha3Code->toAlpha2()->value; # US

Country

A Country instance can be created using either an Alpha-2 or Alpha-3 code, along with an optional country name. There are two main methods to create a Country object: from (which accepts objects) and fromString (which accepts strings).

Creating from objects

You can create a Country instance using the from method by providing an Alpha2Code or Alpha3Code object. Optionally, you can pass the name of the country. If no name is provided, the default is the English version of the country name.

$country = Country::from(alphaCode: Alpha2Code::UNITED_STATES_OF_AMERICA); $country->name; # United States of America $country->alpha2->value; # US $country->alpha3->value; # USA

or

$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA); $country->name; # United States of America $country->alpha2->value; # US $country->alpha3->value; # USA

If you want to specify a custom name:

$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA, name: 'United States'); $country->name; # United States $country->alpha2->value; # US $country->alpha3->value; # USA

Creating from string

Alternatively, you can create a Country instance using the fromString method, which accepts an Alpha-2 or Alpha-3 code as a string. This method is useful when the alpha code is provided as a string.

$country = Country::fromString(alphaCode: 'US'); $country->name; # United States of America $country->alpha2->value; # US $country->alpha3->value; # USA

You can also pass a custom country name when using the fromString method:

$country = Country::fromString(alphaCode: 'USA', name: 'United States'); $country->name; # United States $country->alpha2->value; # US $country->alpha3->value; # USA

License

Country is licensed under MIT.

Contributing

Please follow the contributing guidelines to contribute to the project.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固