PHP code example of czachor / polish-id-validators

1. Go to this page and download the library: Download czachor/polish-id-validators 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/ */

    

czachor / polish-id-validators example snippets


   
   use Czachor\PolishIdValidators\Entities\PwzEntity;
  
   $id = new PwzEntity('5425740');
   

   
   use Czachor\PolishIdValidators\Entities\PwzfEntity;
  
   $id = new PwzfEntity('09014954');
   

   
   use Czachor\PolishIdValidators\Entities\PwzpEntity;
  
   $id = new PwzpEntity('0201234P');
   

   
   use Czachor\PolishIdValidators\Entities\PwzdlEntity;
  
   $id = new PwzdlEntity('3143');
   


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!';
}


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);

// ...

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


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

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);
// ...