PHP code example of assurance-maladie / nir-validation

1. Go to this page and download the library: Download assurance-maladie/nir-validation 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/ */

    

assurance-maladie / nir-validation example snippets


use Cnamts\Nir\Constraints\Nir;
use Symfony\Component\Validator\Validation;

$validator = Validation::createValidator();
$violations = $validator->validate('2 84 05 88 321 025 30', [new Nir()]);

if (count($violations) !== 0) {
    echo '<ul>';
    foreach ($violations as $violation) {
        echo '<li>'.$violation->getMessage().'</li>';
    }
    echo '</ul>';
}

// src/Entity/User.php
namespace App\Entity;

// ...
use Cnamts\Nir\Constraints as Assert;

class User
{
    /**
     * @Assert\Nir
     */
    private $identifier;
}

// src/Entity/User.php
namespace App\Entity;

// ...
use Cnamts\Nir\Constraints as Assert;

class User
{
    #[Assert\Nir]
    private $identifier;
}

// src/Entity/User.php
namespace App\Entity;

// ...
use Cnamts\Nir\Constraints\Nir;
use Symfony\Component\Validator\Mapping\ClassMetadata;

class User
{
    private $identifier;

    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('identifier', new Nir());
    }
}