PHP code example of tourze / user-id-idcard-bundle
1. Go to this page and download the library: Download tourze/user-id-idcard-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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);
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;
}
}
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
}
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.