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

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

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

tourze/gb-t-3304

最新稳定版本:0.0.3

Composer 安装命令:

composer require tourze/gb-t-3304

包简介

PHP 8.1+ implementation of GB/T 3304-1991 standard - Chinese nationalities with numeric and alpha codes

README 文档

README

English | 中文

Latest Version Build Status Quality Score Total Downloads PHP Version Require Coverage Status License

Introduction

This package implements the GB/T 3304-1991 standard "Names of nationalities of China in romanization with codes" as a type-safe PHP 8.1+ enum. It provides both numeric (01-56) and two-letter (HA-JN) codes for all 56 officially recognized Chinese ethnic groups, with convenient integration interfaces for modern PHP applications.

Overview

GB/T 3304-1991 is a Chinese national standard that defines the romanization and coding system for Chinese ethnic groups. This package provides a modern PHP implementation using enums, making it easy to work with Chinese nationality data in a type-safe manner.

Features

  • Complete Coverage: All 56 officially recognized Chinese ethnic groups
  • Dual Coding System: Both numeric codes (01-56) and two-letter codes (HA-JN)
  • Type Safety: Modern PHP 8.1+ enum implementation
  • Easy Integration: Implements Labelable, Itemable, and Selectable interfaces
  • Clean API: Simple methods for code, label, and mapping conversion
  • Well Tested: Comprehensive PHPUnit test suite with 100% coverage
  • Standards Compliant: Follows GB/T 3304-1991 specification exactly

Installation

Requirements:

  • PHP >= 8.1
  • Composer
  • Dependency: tourze/enum-extra ~0.1.0

Install via Composer:

composer require tourze/gb-t-3304

Quick Start

use Tourze\GBT3304\Nationality;

// Get numeric code
$code = Nationality::Han->value; // "01"

// Get Chinese label
$label = Nationality::Han->getLabel(); // "汉族"

// Get two-letter code
$alphaCode = Nationality::Han->toCode(); // "HA"

Advanced Usage

Getting All Nationalities

// Get all nationality options for forms/selects
$options = Nationality::getSelectOptions();
// Returns: ['01' => '汉族', '02' => '蒙古族', ...]

// Get as items for API responses
$items = Nationality::getItems();
// Returns: [['value' => '01', 'label' => '汉族'], ...]

Finding by Code

// From numeric code
$nationality = Nationality::from('01'); // Han

// From alpha code (you'll need to implement this if needed)
$han = array_search('HA', array_map(fn($n) => $n->toCode(), Nationality::cases()));

Integration with Forms

// Symfony forms
$builder->add('nationality', ChoiceType::class, [
    'choices' => Nationality::getSelectOptions(),
]);

// Laravel
Form::select('nationality', Nationality::getSelectOptions());

API Reference

Methods

  • getLabel(): string - Returns the Chinese name of the nationality
  • toCode(): string - Returns the two-letter code
  • value - The numeric code (01-56)
  • getSelectOptions(): array - Returns all options for dropdowns
  • getItems(): array - Returns all items for API responses

Interfaces

  • Labelable - Provides getLabel() method
  • Itemable - Provides getItems() static method
  • Selectable - Provides getSelectOptions() static method

Development

Running Tests

# Run all tests
composer test

# Run with coverage
composer test-coverage

# Run PHPStan
composer analyse

Code Quality

This package maintains high code quality standards:

  • PHPStan Level 9 (maximum)
  • 100% test coverage
  • PSR-12 coding standards
  • No external dependencies except tourze/enum-extra

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Issues: Report bugs or request features via GitHub Issues
  2. Pull Requests: Fork the repo and submit PRs against the main branch
  3. Code Style: Follow PSR-12 coding standards
  4. Testing: Ensure all tests pass and add tests for new features
  5. Documentation: Update README and docblocks as needed

Development Setup

git clone https://github.com/tourze/gb-t-3304.git
cd gb-t-3304
composer install
composer test

License

MIT License. See LICENSE for details.

Related Standards

Security

If you discover any security-related issues, please email security@tourze.org instead of using the issue tracker.

统计信息

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

GitHub 信息

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

其他信息

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