ajaydev / pin-generator
dev-main
2023-04-11 10:21 UTC
Requires
- php: ^7.2.5|^8.2
- illuminate/support: ^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2024-09-11 13:06:22 UTC
README
此Composer包用于Laravel创建唯一标识符,在本例中为PIN(个人识别码),适用于门锁等。每次代码执行时,至少返回一个符合以下条件的PIN
• The initial intention is that each PIN comprises of four numeric digits (e.g. “2845”),
• This package will not generate “obvious” numbers. This can be handled
通过编程方式考虑以下限制,但允许以后添加更多
-> Palindromes
• Invalid examples include : 2332,5555 etc.
-> Sequential numbers
• Invalid examples Include : 0123,1234,1235etc.
-> Repeating numbers
• Invalid examples Include : 1115,7377 etc.
-> As an example, 4942 would be a PIN that passes these 3 restrictions.
• This package will provide the PINs in an apparently random order.
• This package will not repeat a PIN until all the preceding valid PINs have been utilised - even if the solution is stopped and started between PINs being returned.
• You can specify the lenght of the pin e.g. 4, 6, 7, 12-digit pins. But the recommendation will be to not use a very big number.
目录
支持
支持的PHP版本为 ^7.2.5 到 ^8.2
支持的Laravel版本为8+
安装
在项目的根目录下运行以下命令来安装pin-generator包
composer require ajaydev/pin-generator dev-main
成功下载此包后,将服务提供者添加到您的
<project_root>/config/app.php
此提供者数组中
'providers' => [ // add this line in your providers array AjayDev\PinGenerator\PinGeneratorServiceProvider::class, ],
此行
AjayDev\PinGenerator\PinGeneratorServiceProvider::class,
使用
完成上述步骤后,您只需在控制器中使用此外观
use AjayDev\PinGenerator\PinGeneratorFacade;
然后
$pin = PinGeneratorFacade::generatePin(2); #at the place of two you can pass your length as per your requirement by default it will be 4 if you remove 2
单元测试用例(可选)
如果您想运行并查看所有测试用例是否工作正常,可以在您的根项目目录中使用此命令。
php artisan test vendor/ajaydev/pin-generator/tests/PinGeneratorTest.php
就这样,您就可以开始了。