2017 © Pedro Peláez
 

symfony-bundle vatin-validator-bundle

A Symfony bundle for for validating VAT identification numbers (VATINs).

image

ricardonavarrom/vatin-validator-bundle

A Symfony bundle for for validating VAT identification numbers (VATINs).

  • Saturday, October 15, 2016
  • by ricardonavarrom
  • Repository
  • 1 Watchers
  • 1 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

VATINValidatorBundle

Build Status Coverage Status Total Downloads SensioLabsInsight, (*1)

A Symfony bundle for for validating VAT identification numbers (VATINs) based on VATINValidator PHP library., (*2)

Installation

This bundle is available on Packagist., (*3)

You can install this bundle using composer, (*4)

$ composer require ricardonavarrom/vatin-validator-bundle

or add the package to your composer.json file directly., (*5)

After you have installed the package, you just need to add the bundle to your AppKernel.php file:, (*6)

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new ricardonavarrom\VATINValidatorBundle\VATINValidatorBundle(),
    // ...
);

Configuration

VATINValidatorBundle requires no initial configuration to get you started., (*7)

Basic usage

The configured validator is available as ricardonavarrom.vatin_validator service. You must assign a valid locale (view availables locales section)., (*8)

$locale = 'es';
$vatin = '56475114V';
$validator = $container->get('ricardonavarrom.vatin_validator');
$vatinIsValid = $validator->validate($vatin, $locale);

Another option is to use a located validator service as ricardonavarrom.vatin_validator.es (view availables locales section)., (*9)

$vatin = '56475114V';
$locatedValidator = $container->get('ricardonavarrom.vatin_validator.es');
$vatinIsValid = $locatedValidator->validate($vatin);

Availables locales

| Locale | Country | Local name | | ------------- | ------------------| -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | es | Spain | Número de Identificación Fiscal (for freelancers or singular persons), Número de Identidad de Extranjero (for foreigners) or Código de Identificación Fiscal (for companies) | | pt | Portugal | Número de identificação fiscal (for freelancers or singular persons) or Número de Identificação de Pessoa Colectiva (for companies) | We are working to implement more availables locales., (*10)

Constraints

VATINValidatorBundle provides the following constraints:, (*11)

| Constraint | Country | Options | | ------------------------ | ------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | VATINEsConstraint | Spain | message: string (default: 'The VATIN "%vatin%" is not a valid "%validationModality%".'). allowLowerCase: boolean (default: true). validationModality: 'NIF', 'NIE' or 'CIF' (by default checks in all validation modalities). | | VATINPtConstraint | Portugal | message: string (default: 'The VATIN "%vatin%" is not a valid "%validationModality%".'). validationModality: 'NIF' or 'NIPC' (by default checks in all validation modalities). | For example:, (*12)

// src/AppBundle/Entity/Customer.php
namespace AppBundle\Entity;

use ricardonavarrom\VATINValidatorBundle\Validator\Constraints\VATINEsConstraint;

class Customer
{
    /**
     * @VATINEsConstraint(
     *  allowLowerCase = false,
     *  validationModality = "NIF"
     * )
     */
    private $vatin;
}

The Versions