tourze/gb-t-2659
Composer 安装命令:
composer require tourze/gb-t-2659
包简介
GB/T 2659 world countries and regions name code
README 文档
README
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, andSelectableinterfaces - Utility methods: Lowercase conversion, array transformation, and more
Installation
Requirements:
- PHP >= 8.1
tourze/enum-extrapackage
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 casesAlpha2Code::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 nametoLowerCase()- Get lowercase country codetoArray()- Convert to array with value and labeltoSelectItem()- Convert to select item formatgenOptions()- Generate all options for forms
Properties
value- The 2-letter country codename- The enum case name (same as value)
Testing
Run tests with PHPUnit:
./vendor/bin/phpunit packages/gb-t-2659/tests
Contributing
- Check existing issues and PRs before submitting new ones
- Follow PSR-12 coding standards
- Add tests for new features
- 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-24