PHP code example of rocketfellows / specific-country-vat-number-format-validators-config

1. Go to this page and download the library: Download rocketfellows/specific-country-vat-number-format-validators-config 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/ */

    

rocketfellows / specific-country-vat-number-format-validators-config example snippets


class DEVatNumberFormatValidatorsConfig extends SpecificCountryVatNumberFormatValidatorsConfig
{
    public function getCountry(): Country
    {
        return ISO3166::DE();
    }

    protected function getDefaultValidator(): CountryVatFormatValidatorInterface
    {
        return new DEVatFormatValidator();
    }
}

$config = new DEVatNumberFormatValidatorsConfig();

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with one item, which is DEVatFormatValidator instance
$config->getValidators();

class AnotherDEVatFormatValidator implements CountryVatFormatValidatorInterface
{
    public function isValid(string $vatNumber): bool
    {
        // add some implementation
    }
}

$config = new DEVatNumberFormatValidatorsConfig(new AnotherDEVatFormatValidator());

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with one item, which is AnotherDEVatFormatValidator instance
$config->getValidators();

$config = new DEVatNumberFormatValidatorsConfig(
    null,
    (
        new CountryVatFormatValidators(
            new AnotherDEVatFormatValidator()
        )
    )
);

// will return Country instance for Germany (according to standard ISO 3166)
$config->getCountry();

// will return CountryVatFormatValidators tuple with two items:
// object instance of DEVatFormatValidator
// and object instance of AnotherDEVatFormatValidator
$config->getValidators();