rocketfellows / country-vat-number-format-validators-config
Requires
- php: >=7.4
- arslanimamutdinov/iso-standard-3166: 1.0.2
- rocketfellows/country-vat-format-validator-interface: 1.1.0
- rocketfellows/tuple: 1.0.0
Requires (Dev)
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^8.5
- roave/security-advisories: dev-latest
- squizlabs/php_codesniffer: 3.6.2
This package is not auto-updated.
Last update: 2024-09-22 13:40:36 UTC
README
此软件包提供了一个配置特定国家增值税号格式验证器的接口。换句话说,该接口帮助明确指定一组(以元组形式)针对特定国家的验证器。此外,本软件包还包括
- 接口的简单实现,形式为DTO;
- 实现特定国家增值税号格式验证器的对象元组。
下面是一个组件类图
安装
composer require rocketfellows/country-vat-number-format-validators-config
依赖
- https://github.com/rocketfellows/country-vat-format-validator-interface v1.1.0
- https://github.com/arslanim/iso-standard-3166 v1.0.2
- https://github.com/rocketfellows/tuple v1.0.0
软件包组件列表
- CountryVatNumberFormatValidatorsConfigInterface - 配置特定国家增值税号格式验证器的接口;
- CountryVatNumberValidatorsConfig - CountryVatNumberFormatValidatorsConfigInterface接口的简单实现,是一个由国家(Country类型的对象)和验证器元组(CountryVatFormatValidatorInterface类型的对象列表)初始化的DTO;
- CountryVatNumberFormatValidatorsConfigs - 国家增值税号格式验证器配置元组,是CountryVatNumberFormatValidatorsConfigInterface类型的对象列表,还提供了一系列通过元组进行搜索的功能;
CountryVatNumberFormatValidatorsConfigInterface描述
配置特定国家增值税号格式验证器的接口。
根据接口必须实现的方法
- getCountry - 国家对象获取器,必须返回类型为arslanimamutdinov\ISOStandard3166\Country的对象;
- getValidators - 增值税号格式验证器元组获取器,必须返回类型为rocketfellows\CountryVatFormatValidatorInterface\CountryVatFormatValidators的对象;
CountryVatNumberValidatorsConfig描述
CountryVatNumberFormatValidatorsConfigInterface接口的简单实现,是一个由国家(Country类型的对象)和验证器元组(CountryVatFormatValidatorInterface类型的对象列表)初始化的DTO。
类构造函数接受两个参数
- $country - arslanimamutdinov\ISOStandard3166\Country的对象实例;
- $validators - 增值税号格式验证器元组,rocketfellows\CountryVatFormatValidatorInterface\CountryVatFormatValidators类型的对象;
对象实例化示例
/** * FirstRUVatNumberValidator and SecondRUVatNumberValidator are implemented CountryVatFormatValidatorInterface */ $validators = new CountryVatFormatValidators(new FirstRUVatNumberValidator(), new SecondRUVatNumberValidator()); $config = new CountryVatNumberValidatorsConfig(Country::RU(), $validators); $config->getCountry(); // will return RU country object $config->getValidators(); // will return $validators tuple
CountryVatNumberFormatValidatorsConfigs描述
国家增值税号格式验证器配置元组。是CountryVatNumberFormatValidatorsConfigInterface类型的对象列表。还提供了一系列通过元组进行搜索的功能。
元组通过其元素进行循环
// implements CountryVatNumberFormatValidatorsConfigInterface $ruVatNumberFormatValidatorsConfig = new CountryVatNumberValidatorsConfig( Country::RU(), new CountryVatFormatValidators(new RUVatNumberFormatValidator()) ); // implements CountryVatNumberFormatValidatorsConfigInterface $deVatNumberFormatValidatorsConfig = new CountryVatNumberValidatorsConfig( Country::DE(), new CountryVatFormatValidators(new DEVatNumberFormatValidator()) ); // implements CountryVatNumberFormatValidatorsConfigInterface $atVatNumberFormatValidatorsConfig = new CountryVatNumberValidatorsConfig( Country::AT(), new CountryVatFormatValidators(new ATVatNumberFormatValidator()) ); $configs = new CountryVatNumberFormatValidatorsConfigs( $ruVatNumberFormatValidatorsConfig, $deVatNumberFormatValidatorsConfig, $atVatNumberFormatValidatorsConfig ); // each $config variable is an instance of CountryVatNumberFormatValidatorsConfigInterface foreach ($configs as $config) { $config->getCountry(); // returns Country of current config $config->getValidators(); // return CountryVatFormatValidators of current config }
CountryVatNumberFormatValidatorsConfigs公共函数
- getCountryValidators(Country $country) - 从元组中返回给定Country对象唯一的验证器(CountryVatFormatValidators对象实例),如果没有给定国家的验证器,则返回空元组;
- getValidatorsByCountryCode(string $countryCode) - 根据给定的国家代码(通过alpha2、alpha3和数字代码搜索)从元组中返回唯一的验证器(CountryVatFormatValidators对象实例),如果给定国家代码没有验证器,则返回空元组;
搜索函数将返回一个CountryVatFormatValidators元组,该元组将包含一个唯一验证器的列表。例如,初始配置元组CountryVatNumberFormatValidatorsConfigs可能包含同一国家的几个配置。在这种情况下,元组将包含所需国家所有配置中的唯一验证器。此外,可以为国家提供一个配置,但该配置可能包含相同的验证器,在这种情况下,所需国家验证器的元组也将由唯一验证器组成。
更多搜索用例可以在测试中找到
- rocketfellows\CountryVatNumberFormatValidatorsConfig\tests\unit\GetCountryValidatorsTest;
- rocketfellows\CountryVatNumberFormatValidatorsConfig\tests\unit\GetValidatorsByCountryCodeTest;
贡献
欢迎提交pull request。如果有重大变更,请首先提出一个问题以进行讨论。
请确保根据需要更新测试。
