tourze / idcard-manage-bundle
提供身份证验证、解析生日性别等功能的 Symfony Bundle
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/idcard-manage-bundle
Requires
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- ionepub/idcard: ^1.1
- knplabs/knp-menu: ^3.7
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher: ^7.3
- symfony/expression-language: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/messenger: ^7.3
- symfony/property-access: ^7.3
- symfony/security-core: ^7.3
- symfony/string: ^7.3
- symfony/yaml: ^7.3
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-ip-bundle: 1.1.*
- tourze/doctrine-snowflake-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/doctrine-track-bundle: 1.1.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-enum-field-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/gb-t-2261: 1.0.*
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^4.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/bundle-dependency: 1.*
- tourze/phpunit-doctrine-entity: 1.*
- tourze/phpunit-enum: 1.*
- tourze/phpunit-symfony-kernel-test: 1.0.*
- tourze/phpunit-symfony-unit-test: 1.*
- tourze/phpunit-symfony-web-test: 1.*
- tourze/symfony-dependency-service-loader: 1.0.*
This package is auto-updated.
Last update: 2025-11-18 11:05:26 UTC
README
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
falseif invalid
getGender(string $number): Gender
Extracts the gender from the ID card number.
- Returns:
Genderenum 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
falseas 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
- PHP 8.1+
- Symfony 6.4+
- ionepub/idcard - Core ID card validation library
- tourze/gb-t-2261 - Gender enum definitions
License
The MIT License (MIT). Please see License File for more information.