tourze / user-id-idcard-bundle
用户身份证验证模块,提供身份证号码的存储、验证和管理功能
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/user-id-idcard-bundle
Requires
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/security-core: ^7.3
- symfony/yaml: ^7.3
- tourze/bundle-dependency: 1.*
- tourze/doctrine-snowflake-bundle: 1.0.*
- tourze/doctrine-timestamp-bundle: 1.0.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/user-id-bundle: 1.0.*
Requires (Dev)
- doctrine/data-fixtures: ^2.0
- doctrine/doctrine-fixtures-bundle: ^4.0
- nesbot/carbon: ^2.72 || ^3
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
- tourze/phpunit-doctrine-entity: 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.*
- tourze/user-service-contracts: 1.*
This package is auto-updated.
Last update: 2025-11-13 18:14:43 UTC
README
A Symfony bundle that provides Chinese ID card identity verification functionality as an extension to the user identity system.
Features
- Chinese ID card identity management
- Integration with user identity system
- Doctrine ORM entity for ID card storage
- Service decorator pattern for extensibility
- Snowflake ID generation support
- Timestamp and blame tracking
Installation
composer require tourze/user-id-idcard-bundle
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
Dependencies
tourze/user-id-bundle: Base identity systemtourze/doctrine-snowflake-bundle: Snowflake ID generationtourze/doctrine-timestamp-bundle: Timestamp trackingtourze/doctrine-user-bundle: User blame tracking
Quick Start
1. Enable the Bundle
Add the bundle to your config/bundles.php:
return [ // ... other bundles Tourze\UserIDIdcardBundle\UserIDIdcardBundle::class => ['all' => true], ];
2. Update Database Schema
php bin/console doctrine:schema:update --force
3. Basic Usage
use Tourze\UserIDIdcardBundle\Entity\IdcardIdentity; use Tourze\UserIDIdcardBundle\Service\UserIdentityIdcardService; // Create ID card identity $idcardIdentity = new IdcardIdentity(); $idcardIdentity->setIdcard('110101199001011234'); $idcardIdentity->setUser($user); // Find by ID card number $identity = $userIdentityService->findByType( IdcardIdentity::IDENTITY_TYPE, '110101199001011234' ); // Get all identities for a user $identities = $userIdentityService->findByUser($user);
Configuration
This bundle extends the tourze/user-id-bundle and requires no additional
configuration. It automatically decorates the UserIdentityService to handle
ID card identities.
Advanced Usage
Custom Validation
You can extend the ID card validation by creating custom validators:
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; class CustomIdcardValidator extends ConstraintValidator { public function validate($value, Constraint $constraint): void { // Custom validation logic if (!$this->isValidIdcard($value)) { $this->context->buildViolation($constraint->message) ->addViolation(); } } private function isValidIdcard(string $idcard): bool { // Implement your custom validation logic return true; } }
Service Integration
use Tourze\UserIDIdcardBundle\Service\UserIdentityIdcardService; class YourService { public function __construct( private UserIdentityIdcardService $identityService ) {} public function processUserIdentity(UserInterface $user): void { $identities = $this->identityService->findByUser($user); foreach ($identities as $identity) { if ($identity->getIdentityType() === IdcardIdentity::IDENTITY_TYPE) { // Process ID card identity } } } }
Entity Structure
The IdcardIdentity entity includes:
id: Snowflake ID (primary key)idcard: Chinese ID card number (18 digits)user: Reference to user entitycreateTime: Creation timestampupdateTime: Last update timestampcreateBy: User who created the recordupdateBy: User who last updated the record
License
MIT