Skip to content

[DEPREACTED] PHP library based on Symfony Validator Component to validate various medical identification numbers used in Poland.

Notifications You must be signed in to change notification settings

czachor/polish-id-validators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[DEPRECATED] Polish ID Validators

Version: 1.3

Pcackage is currently marked as deprecated. A new version is coming soon.

PHP library based on Symfony Validator Component to validate various medical identification numbers used in Poland.

Only algorithmical validation mostly based on a check digit. It does not query official medical registries to fetch any data or if a record (ID) exists at all.

Available validators

Requirements

PHP 7.2+.

Install

Via Composer

$ composer require czachor/polish-id-validators

Usage

All ID must be passed as strings.

Direct method

<?php
use Czachor\PolishIdValidators\Entities\PwzEntity;
use Czachor\PolishIdValidators\Validator;

$pwz_id = new PwzEntity('5425740'); // Polish medical licence ID
/** @var Symfony\Component\Validator\ConstraintViolationListInterface $obj_validator */
$violations = Validator::validate($pwz_id);

if ($violations->count() > 0) {
    foreach ($violations as $violation) {
        echo 'Error! ' . $violation->getMessage();
    }
} else {
    echo 'Valid!';
}

With Symfony Component:

<?php
use Czachor\PolishIdValidators\Entities\PwzEntity;
use Symfony\Component\Validator\Validation;

$pwz_id = new PwzEntity('5425740'); // Polish medical licence ID 
$validator = Validation::createValidatorBuilder()
    ->addMethodMapping('loadValidatorMetadata')
    ->getValidator();
$violations = $validator->validate($pwz_id);

// ...

Translation

Translation uses Symfony Translation Component.

Available languages:

  • English (default) - en_US
  • Polish - pl_PL

How to use:

<php
$violations = Validator::validate($pwz_id, 'pl_PL');

If your language is unsupported, you can add it manually:

<?php
$violations = Validator::validate($pwz_id, 'pt_BR', $path_to_your_php_resource_file);

Or if you want to use a different loader:

use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Validator\Validation;
use Czachor\PolishIdValidators\Entities\PwzEntity;

$translator = new Translator('fr_FR');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', [
    'Hello World!' => 'Bonjour',
], 'fr_FR');

$validator = Validation::createValidatorBuilder()
    ->addMethodMapping('loadValidatorMetadata')
    ->setTranslator($translator)
    ->getValidator();

$pwz_id = new PwzEntity('5425740'); // Polish medical licence ID 
$violations = $validator->validate($pwz_id);
// ...

Todo

  • More validators
  • Annotations
  • More translations

License

The MIT License (MIT).

About

[DEPREACTED] PHP library based on Symfony Validator Component to validate various medical identification numbers used in Poland.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages