davidianbonner / cli-phone-number-validator
使用Google的libphonenumber的CLI电话号码验证器。
1.0.3
2017-11-17 09:17 UTC
Requires
- php: >=7.1
- giggsey/libphonenumber-for-php: ^8.8
- laravel-zero/framework: 4.0.*
- vlucas/phpdotenv: ^2.4
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ~6.4
- squizlabs/php_codesniffer: ^2.3
This package is auto-updated.
Last update: 2024-09-08 20:56:27 UTC
README
安装
使用composer安装应用程序
$ composer create-project davidianbonner/cli-phone-number-validator
要为部署创建应用程序的独立PHAR,请运行
$ php number-validator app:build number-validator
这将输出一个PHAR文件到build目录。
使用方法
验证器附带预构建的GB和Channel Islands移动命令:validate:uk-mobile。有两种处理和验证数字的方式
列表源
将电话号码列表传递给验证器。
$ php number-validator validate:uk-mobile "07712345678" "07712341234" "07283 123 32"
文件源
传递每行一个电话号码的文件。
$ php number-validator validate:uk-mobile ./path/to/file --file
输出目录
使用独立的PHAR时需要输出目录。
$ php number-validator validate:uk-mobile ./path/to/file --file --output=/path/to/output/directory
添加新验证器
可以通过最小的努力添加新验证器。首先在app/Commands中创建一个新命令,并扩展BaseValidatorCommand。
<?php namespace App\Commands; class ValidateESFixedLineCommand extends BaseValidatorCommand { protected $signature = 'validate:es-fixedline {source* : A list of numbers or files to validate against} {--file : Specifies that the source is a list of files} {--output= : Specifies that the output path}'; protected $description = 'Validate Spanish fixed line numbers and ouput to a CSV'; public function makeValidatorForNumer($number): PhoneNumberValidator { // The country code is only required when no dialing code is present in the number. return app(PhoneNumberValidator::class)->make($number, 'ES'); } public function isNumberValid(PhoneNumberValidator $validator): bool { return ($validator->isValidFixedLine() && $validator->isValidForCountry('ES')); } }
许可证
CLI电话号码验证器是一个开源软件,许可协议为MIT许可证。