mpsoft-digital/keygen
Composer 安装命令:
composer require mpsoft-digital/keygen
包简介
Pattern-based key generator
README 文档
README
Essa documentação está disponível também em Português do Brasil.
This plugin is under development and may exhibit unexpected behavior while using it, please report any bugs or errors you find when using this solution, so that we can make it the best possible for your use!
The Keygen plugin is a key or serial generator based on user-defined mask patterns. The plugin is able to generate keys like the example below:
6W2F-4RJB-KV0Z-ADA6-4SJ2
It can be used to generate keys for several purposes, some examples are:
- Unique links to reset passwords
- Registration via invitation link
- Two-Factor authentication codes
- File sharing links
- Product redemption keys
- Discount coupons
- Referral codes
Installation
Fisrt, run the following command in your project:
composer require kaiopiola/keygen
Then, call the main class on the PHP file you want to load it:
use Kaiopiola\Keygen\Key;
How Keygen works
How to create a new key
To create a new key, just instantiate the class in a variable, and then define its configuration parameters, as shown in the example below:
# Instantiating class in a variable: $exampleKey = new Key; # Setting parameters: $exampleKey->setPattern("XXXX-NNNN-LLLL"); // Defines the pattern that the code will use to define its new key. // The letters represent the type of content that can be used in that space, as per the rule: // X - Any letter or number // N - Numbers only as defined // L - Letters only as defined // Any other characters like dashes, dots, slashes, and even other letters and numbers, will not be replaced. // If this property is not defined, the following will be used by default: XXXXX-XXXXX-XXXXX $exampleKey->setNumbers("789"); // Defines the numbers that can compose your key, if not defined, it will use by default "0123456789" $exampleKey->setLetters("ABC"); // Defines the letters that can compose your key, if not defined, it will use by default "ABCDEFGHIJKLMNOPQRSTUVWXYZ" $exampleKey->generate(); // Generate your key and return a string value with the result
How to create a new unique key
⚠️ This particular feature is still under development and you may experience issues or instability when using it!
If you find any problems or bugs, please create a new issue tagged bug! ⚠️
You also have the option to generate an unique key to avoid duplicates, using the example below:
$exampleKey->setExistingKeys([]); // Defines the existing keys that the code will avoid duplicates. Must be type array. $exampleKey->generateUnique(); // Generate your key and return a string value with the result
This is also compatible with setPattern, setNumbers and setLetters too!
Considerations
This project is open to contributions, whether with suggestions or improvements to the code of any kind. Feel free to participate in its development.
License
MIT License (MIT). Please, read the License File for more informations.
mpsoft-digital/keygen 适用场景与选型建议
mpsoft-digital/keygen 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mpsoft-digital/keygen 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mpsoft-digital/keygen 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 64.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-19