tourze/idcard-manage-bundle 问题修复 & 功能扩展

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

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

tourze/idcard-manage-bundle

最新稳定版本:0.1.0

Composer 安装命令:

composer require tourze/idcard-manage-bundle

包简介

提供身份证验证、解析生日性别等功能的 Symfony Bundle

README 文档

README

English | 中文

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

A Symfony bundle for Chinese ID card management and validation.

Features

  • ✅ Chinese ID card format validation
  • ✅ Birthday extraction with custom separator support
  • ✅ Gender detection with enum support (GB/T 2261 standard)
  • ✅ Full Symfony framework integration
  • ✅ Comprehensive test coverage
  • ⚠️ Two-element verification (placeholder for external API integration)

Installation

composer require tourze/idcard-manage-bundle

Quick Start

<?php

use Tourze\IdcardManageBundle\Service\IdcardService;
use Tourze\GBT2261\Gender;

class YourController
{
    public function __construct(
        private IdcardService $idcardService
    ) {}

    public function validateIdcard(string $idNumber): void
    {
        // Validate ID card number
        if ($this->idcardService->isValid($idNumber)) {
            echo "Valid ID card number";
            
            // Get birthday
            $birthday = $this->idcardService->getBirthday($idNumber);
            if ($birthday !== false) {
                echo "Birthday: " . $birthday;
            }
            
            // Get gender
            $gender = $this->idcardService->getGender($idNumber);
            match ($gender) {
                Gender::MAN => echo "Male",
                Gender::WOMAN => echo "Female",
                default => echo "Unknown gender",
            };
        } else {
            echo "Invalid ID card number";
        }
    }
}

Configuration

Add the bundle to your config/bundles.php:

<?php

return [
    // ... other bundles
    Tourze\IdcardManageBundle\IdcardManageBundle::class => ['all' => true],
];

API Documentation

Service Methods

isValid(string $number): bool

Validates if the ID card number follows basic format rules.

getBirthday(string $number, string $sep = '-'): string|false

Extracts the birthday from the ID card number.

  • $number: The ID card number
  • $sep: Date separator (default: '-')
  • Returns: Birthday string or false if invalid

getGender(string $number): Gender

Extracts the gender from the ID card number.

  • Returns: Gender enum value (MAN, WOMAN, UNKNOWN)

twoElementVerify(string $certName, string $certNo): bool

Verifies the ID card number with the holder's name using external API.

  • Currently returns false as it requires third-party API integration

Testing

# Run tests
./vendor/bin/phpunit packages/idcard-manage-bundle/tests

# Run static analysis
php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/idcard-manage-bundle

Contributing

Please see CONTRIBUTING.md for details.

Dependencies

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-20