yzalis/id-obfuscator
最新稳定版本:1.0.0
Composer 安装命令:
composer require yzalis/id-obfuscator
包简介
An efficient reversible ID obfuscator originaly based on base 62 encoding.
README 文档
README
IdObfuscator is a library which helps you to hide your original IDs. The library helps you to encode and decode these IDs
Basic Usage
Instantiate the obfuscator
<?php // create a new IdObfuscator instance $idObfuscator = new \IdObfuscator\IdObfuscator();
Then you can encode your id and decode the generated hash.
$hash = $idObfuscator->encode(10); // $hash contain "A" $id = $idObfuscator->decode('A'); // $id contain "10"
Here are some examples with the default set:
10 <=> 'A'
35 <=> 'Z'
36 <=> 'a'
61 <=> 'z'
62 <=> '10'
63 <=> '11'
134 <=> '2A'
3843 <=> 'zz'
3844 <=> '100'
144513 <=> 'bar'
160754 <=> 'foo'
238327 <=> 'zzz'
238328 <=> '1000'
Custom set
By default, the library use the following characters set to encode and decode.
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
You can use the static method randomizeDefaultSet to shuffle the default set.
$myRandomSet = IdObfuscator::randomizeDefaultSet();
Or you can also use you own custom set.
$idObfuscator = new IdObfuscator('cusTOMS3t'); $idObfuscator->encode(1); // will return "c"; $idObfuscator->decode('t'); // will return "9";
Unit Tests
To run unit tests, you'll need cURL and a set of dependencies you can install using Composer:
curl -sS https://getcomposer.org/installer | php
php composer.phar install
Once installed, just launch the following command:
./vendor/bin/phpunit
You're done.
Credits
- Benjamin Laugueux benjamin@yzalis.com
- All contributors
License
IdObfuscator is released under the MIT License. See the bundled LICENSE file for details.
统计信息
- 总下载量: 213
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-13