ricardonavarrom/vatin-validator-bundle

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

1.2.5 2016-10-15 12:04 UTC

This package is not auto-updated.

Last update: 2024-11-18 14:17:17 UTC


README

Build Status Coverage Status Total Downloads SensioLabsInsight

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

Installation

This bundle is available on Packagist.

You can install this bundle using composer

$ composer require ricardonavarrom/vatin-validator-bundle

or add the package to your composer.json file directly.

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

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

Configuration

VATINValidatorBundle requires no initial configuration to get you started.

Basic usage

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

$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).

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

Availables locales

Constraints

VATINValidatorBundle provides the following constraints:

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

use ricardonavarrom\VATINValidatorBundle\Validator\Constraints\VATINEsConstraint;

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