Skip to content

This package provides a preconfigured configuration class for vat number format validators for Denmark country. Is an extension of the package https://github.com/rocketfellows/specific-country-vat-number-format-validators-config.

Notifications You must be signed in to change notification settings

rocketfellows/dk-vat-number-format-validators-config

Repository files navigation

Denmark vat number format validators config

Code Coverage Badge

This package provides a preconfigured configuration class for vat number format validators for Denmark country. Is an extension of the package https://github.com/rocketfellows/specific-country-vat-number-format-validators-config.

Installation

composer require rocketfellows/dk-vat-number-format-validators-config

Dependencies

References

List of package components

  • rocketfellows\DKVatNumberFormatValidatorsConfig\DKVatNumberFormatValidatorsConfig - preconfigured configuration class for vat number format validators for Denmark country;

DKVatNumberFormatValidatorsConfig description

A configuration class that provides a match for the vat number format validators for the country Denmark.

Class interface:

  • getCountry - returns Denmark Country instance;
  • getValidators - returns validators tuple

When initializing the default configuration, the getValidators function returns a tuple with a single validator - an instance of DKVatFormatValidator.

$config = new DKVatNumberFormatValidatorsConfig();

$config->getCountry();      // returns Denmark Country instance
$config->getValidators();   // returns CountryVatFormatValidators with one item - instance of DKVatFormatValidator

You can override the default validator by initializing the configuration class object with a new default validator through the first parameter of the class constructor. Attention - validator must implement interface CountryVatFormatValidatorInterface.

$newDefaultValidator = new NewDefaultValidator();                       // instance of CountryVatFormatValidatorInterface
$config = new DKVatNumberFormatValidatorsConfig($newDefaultValidator);  // initialize with new default validator

$config->getValidators();   // returns CountryVatFormatValidators with one item - $newDefaultValidator

You can add additional validators to the default validator via the second constructor parameter.

Attention - additional validators parameter must be instance of tuple CountryVatFormatValidators. And each additional validator must implement interface CountryVatFormatValidatorInterface.

$firstAdditionalValidator = new FirstAdditionalValidator();   // instance of CountryVatFormatValidatorInterface
$secondAdditionalValidator = new SecondAdditionalValidator(); // instance of CountryVatFormatValidatorInterface

$config = new DKVatNumberFormatValidatorsConfig(
    null,
    (
        new CountryVatFormatValidators(
            $firstAdditionalValidator,
            $secondAdditionalValidator
        )
    )
);

// returns CountryVatFormatValidators with three items:
// default preconfigured validator by default - instance of DKVatFormatValidator
// $firstAdditionalValidator - from additional tuple
// $secondAdditionalValidator - from additional tuple
$config->getValidators();

You can also completely rebuild the configuration by passing the default validator and a tuple of additional validators to the config class constructor.

$defaultValidator = new DefaultValidator();                   // instance of CountryVatFormatValidatorInterface
$firstAdditionalValidator = new FirstAdditionalValidator();   // instance of CountryVatFormatValidatorInterface
$secondAdditionalValidator = new SecondAdditionalValidator(); // instance of CountryVatFormatValidatorInterface

$config = new DKVatNumberFormatValidatorsConfig(
    $defaultValidator,
    (
        new CountryVatFormatValidators(
            $firstAdditionalValidator,
            $secondAdditionalValidator
        )
    )
);

// returns CountryVatFormatValidators with three items:
// $defaultValidator from constructor first parameter
// $firstAdditionalValidator - from additional tuple
// $secondAdditionalValidator - from additional tuple
$config->getValidators();

More use case examples can be found in the package's unit tests.

Contributing

Welcome to pull requests. If there is a major changes, first please open an issue for discussion.

Please make sure to update tests as appropriate.