PHP code example of sllh / iso-codes-validator

1. Go to this page and download the library: Download sllh/iso-codes-validator 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/ */

    

sllh / iso-codes-validator example snippets


use Symfony\Component\Validator\Validation;
use SLLH\IsoCodesValidator\Constraints\Vat;

$validator = Validation::createValidator();

$violations = $validator->validateValue('DE123456789', new Vat());

use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
use SLLH\IsoCodesValidator\Constraints as IsoCodesAssert;

class Company
{
    /**
     * @Assert\NotBlank
     * @IsoCodesAssert\Siret
     */
    private $siret;

    /**
     * @Assert\NotBlank
     * @IsoCodesAssert\Siren
     */
    private $siren;

    /**
     * @IsoCodesAssert\Vat
     */
    private $vat;

    /**
     * @IsoCodesAssert\ZipCode(country = "FR")
     */
    private $zipCode;

    public function __construct($siret, $siren, $vat, $zipCode)
    {
        $this->siret = $siret;
        $this->siren = $siren;
        $this->vat = $vat;
        $this->zipCode = $zipCode
    }
}

$validator = Validation::createValidatorBuilder()
    ->enableAnnotationMapping()
    ->getValidator();

$company = new Company('48853781200015', '432167567', 'DE123456789', '59000');

$violations = $validator->validate($company);
 php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new SLLH\IsoCodesValidator\Bridge\Symfony\Bundle\SLLHIsoCodesValidatorBundle(),
    );
}