Interfaces, traits, and filters for dealing with VAT ID numbers
$ composer require germania-kg/vatidno
Provides a method VatIdNo to retrieve the VATIN as string.
use Germania\VatIdNo\VatIdNoProviderInterface;
/**
* @return string
*/
public function getVatIdNo();
Extends VatIdNoProviderInterface and provides a method setVatIdNo, allowing you to set the VATIN.
use Germania\VatIdNo\VatIdNoProviderInterface;
/**
* @param string $vatin
* @return self
*/
public function setVatIdNo( $vatin );
public function getVatIdNo();
Implements the VatIdNoProviderInterface and provides a public property vatin:
use Germania\VatIdNo\VatIdNoProviderInterface;
use Germania\VatIdNo\VatIdNoProviderTrait;
class MyClass implements VatIdNoProviderInterface {
use VatIdNoProviderTrait;
public function __construct( $vatin ) {
$this->vatin = $vatin;
}
}
Implements the VatIdNoAwareInterface. Utilizes the VatIdNoProviderTrait.
use Germania\VatIdNo\VatIdNoAwareInterface;
use Germania\VatIdNo\VatIdNoAwareTrait;
class MyClass implements VatIdNoAwareInterface {
use VatIdNoAwareTrait;
}
// Simple example
$object1 = new MyClass;
$object1->setVatIdNo( "XY000000" );
// Fluent interface
echo $object1->setVatIdNo( "XY000000" )->vatin;
// Setting using VatIdNoProviderInterface
$object2 = new MyClass;
$object2->setVatIdNo( $object1 );
Filter for records that do provide a VATIN. These may be:
- Arrays with
vatin
key, and non-empty value - Objects with
vatin
property, and non-empty value - Instances of
VatIdNoProviderInterface
where getVatIdNo results not empty
<?php
use Germania\VatIdNo\Filters\WithVatIdNoFilterIterator;
$records = new \ArrayIterator( ask_database() );
// Allow custom field names in arrays or objects
$records_with_vatin = new WithoutVatIdNoFilterIterator( $records );
$records_with_vatin = new WithoutVatIdNoFilterIterator( $records, "ust_id" );
foreach( $records_with_vatin as $item):
// Do things like validating
endforeach;
Filter for records that do not provide a VATIN. These may be:
- Arrays lacking
vatin
key, or emptyvatin
element - Objects lacking
vatin
property, or emptyvatin
property - Instances of
VatIdNoProviderInterface
where getVatIdNo results empty
<?php
use Germania\VatIdNo\Filters\WithoutVatIdNoFilterIterator;
$records = new \ArrayIterator( ask_database() );
// Allow custom field names in arrays or objects
$records_lacking = new WithoutVatIdNoFilterIterator( $records );
$records_lacking = new WithoutVatIdNoFilterIterator( $records, "ust_id" );
foreach( $records_lacking as item):
//...
endforeach;
To validate the VAT ID numbers, use a dedicated package like David de Boer's ddeboer/vatin package.
$ git clone https://github.com/GermaniaKG/VatIdNo.git
$ cd VatIdNo
$ composer install
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test
# or
$ vendor/bin/phpunit