承接 tourze/gb-t-2659 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tourze/gb-t-2659

Composer 安装命令:

composer require tourze/gb-t-2659

包简介

GB/T 2659 world countries and regions name code

README 文档

README

English | 中文

Latest Version Total Downloads PHP Version Build Status Coverage Status License

A PHP implementation of GB/T 2659 country and region codes (2-letter) based on PHP 8.1 enums.

Features

  • Complete GB/T 2659 implementation: All 249 countries and regions included
  • Type-safe enums: Built on PHP 8.1 backed enums for maximum type safety
  • Bilingual support: Chinese labels with English documentation
  • Form integration: Ready-to-use with dropdown lists and form components
  • Extensible: Implements Labelable, Itemable, and Selectable interfaces
  • Utility methods: Lowercase conversion, array transformation, and more

Installation

Requirements:

  • PHP >= 8.1
  • tourze/enum-extra package

Install via Composer:

composer require tourze/gb-t-2659

Quick Start

<?php

use Tourze\GBT2659\Alpha2Code;

// Basic usage
$china = Alpha2Code::CN;
echo $china->value;        // Output: CN
echo $china->getLabel();   // Output: 中国
echo $china->toLowerCase(); // Output: cn

// Create from string
$usa = Alpha2Code::from('US');
echo $usa->getLabel();     // Output: 美国

// Safe creation with tryFrom
$code = Alpha2Code::tryFrom('UK');
if ($code === null) {
    echo "Invalid code";
}

// Get all countries
$allCountries = Alpha2Code::cases();
echo count($allCountries); // Output: 249

Advanced Usage

Form Integration

// Generate options for dropdown
$options = Alpha2Code::genOptions();
// Returns: [['value' => 'CN', 'label' => '中国'], ...]

// Convert to array
$array = Alpha2Code::CN->toArray();
// Returns: ['value' => 'CN', 'label' => '中国']

// Convert to select item
$item = Alpha2Code::CN->toSelectItem();
// Returns: ['value' => 'CN', 'label' => '中国', 'text' => '中国', 'name' => '中国']

Country Filtering

// Filter Asian countries
$asianCountries = [
    Alpha2Code::CN, Alpha2Code::JP, Alpha2Code::KR,
    Alpha2Code::IN, Alpha2Code::SG, Alpha2Code::TH
];

$userCountry = Alpha2Code::from('JP');
if (in_array($userCountry, $asianCountries)) {
    echo "User is from Asia";
}

API Reference

Methods

  • Alpha2Code::cases() - Get all enum cases
  • Alpha2Code::from(string $value) - Create enum from string (throws on invalid)
  • Alpha2Code::tryFrom(string $value) - Create enum from string (returns null on invalid)
  • getLabel() - Get Chinese country name
  • toLowerCase() - Get lowercase country code
  • toArray() - Convert to array with value and label
  • toSelectItem() - Convert to select item format
  • genOptions() - Generate all options for forms

Properties

  • value - The 2-letter country code
  • name - The enum case name (same as value)

Testing

Run tests with PHPUnit:

./vendor/bin/phpunit packages/gb-t-2659/tests

Contributing

  1. Check existing issues and PRs before submitting new ones
  2. Follow PSR-12 coding standards
  3. Add tests for new features
  4. Update documentation when needed

License

The MIT License (MIT). Please see License File for more information.

Changelog

See Git commit history for detailed changelog information.

tourze/gb-t-2659 适用场景与选型建议

tourze/gb-t-2659 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.68k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 tourze/gb-t-2659 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tourze/gb-t-2659 我们能提供哪些服务?
定制开发 / 二次开发

基于 tourze/gb-t-2659 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-24