princejohnsantillan/id-base-converter
Composer 安装命令:
composer require princejohnsantillan/id-base-converter
包简介
Encode integer IDs using a preset or customized symbol set
README 文档
README
This package makes converting integer IDs into encoded strings and vice versa easy. You can use a preset symbol set, or you can define your own.
This can be useful if you want to add a layer of obfuscation to your integer IDs by encoding them into strings, which you can then decode back to the original ID.
For example, if you have a URL https://example-dashboard.com/user/123 and you don't want to expose the exact database ID to the public, you can encode the ID. The URL could then become https://example-dashboard.com/user/3F.
Requirement
PHP 8.0 or higher
Installation
composer require princejohnsantillan/id-base-converter
Usage
To use the available symbol sets:
use IdBaseConverter\IdBase; // Symbols: '0123456789abcdef' $converter = IdBase::asBase16(); // Symbols: '0123456789ABCDEF' $converter = IdBase::asBase16uc(); // Symbols: '0123456789abcdefghijklmnopqrstuvwxyz' $converter = IdBase::asBase36(); // Symbols: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' $converter = IdBase::asBase36uc(); // Symbols: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' $converter = IdBase::asAlphanumeric();
To use your own symbol set:
use IdBaseConverter\IdBase; $converter = IdBase::symbols("0a1b2c3d4e5f6g7h8i9j");
Converting an integer ID:
use IdBaseConverter\IdBase; IdBase::asBase16()->toString(123); // 7b IdBase::asBase36uc()->toString(123); // 3F IdBase::symbols("0a1b2c3d4e5f6g7h8i9j")->toString(123); // 3b
Converting an encoded string back to an integer ID:
use IdBaseConverter\IdBase; IdBase::asBase16()->toInteger('7b'); // 123 IdBase::asBase16uc()->toInteger('3F'); // 123 IdBase::symbols("0a1b2c3d4e5f6g7h8i9j")->toInteger('3b'); // 123
Alternatively, you can use the convert method to convert an integer ID into an encoded string or vice versa:
use IdBaseConverter\IdBase; IdBase::asAlphanumeric()->convert(12345); // 3d7 IdBase::asAlphanumeric()->convert('3d7'); // 12345
princejohnsantillan/id-base-converter 适用场景与选型建议
princejohnsantillan/id-base-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.36k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「encode」 「decode」 「base converter」 「id converter」 「integer to string」 「string to integer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 princejohnsantillan/id-base-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 princejohnsantillan/id-base-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 princejohnsantillan/id-base-converter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
yii2 simialbi base
Runn Me! Serialization Library
Yii2 js base class
Shareable classes and traits useful for any PHP project
With the JSON codec you will be able to encode into and decode from JSON data in an object oriented way. It wraps PHP's functions `json_encode()` and `json_decode()`.
统计信息
- 总下载量: 16.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-26