takaram/uuid47
最新稳定版本:0.1.0
Composer 安装命令:
composer require takaram/uuid47
包简介
PHP implementation of UUIDv47
README 文档
README
This is a PHP implementation of UUIDv47.
UUIDv47 allows you to encode a UUIDv7 into a UUIDv4 and back again. Store UUIDv7 in a database, which is timestamp-based and sortable, while showing it to users as a random-looking UUIDv4.
Installation
Install the package with Composer:
composer require takaram/uuid47
Usage
Here is a simple example of how to use this library:
<?php declare(strict_types=1); use Ramsey\Uuid\Uuid; use Takaram\Uuid47\Uuid47; require __DIR__ . '/vendor/autoload.php'; // Example: parse a v7 from DB, emit façade, then decode back. $key = hex2bin('0123456789abcdeffedcba9876543210'); // Example v7 string (any valid v7 will do): $uuid = Uuid::fromString('018f2d9f-9a2a-7def-8c3f-7b1a2c4d5e6f'); $facade = Uuid47::encode($uuid, $key); $back = Uuid47::decode($facade, $key); echo "v7 in : $uuid\n"; echo "v4 out: $facade\n"; echo "back : $back\n";
Alternatively, you can use Takaram\Uuid47\Codec class:
<?php declare(strict_types=1); use Ramsey\Uuid\Uuid; use Takaram\Uuid47\Codec; require __DIR__ . '/vendor/autoload.php'; $key = hex2bin('0123456789abcdeffedcba9876543210'); $codec = new Codec($key); $uuid = Uuid::fromString('018f2d9f-9a2a-7def-8c3f-7b1a2c4d5e6f'); $facade = $codec->encode($uuid, $key); $back = $codec->decode($facade, $key); echo "v7 in : $uuid\n"; echo "v4 out: $facade\n"; echo "back : $back\n";
Testing
To run the tests, you will need to have PHPUnit installed as a dev dependency:
composer install --dev ./vendor/bin/phpunit
Original Implementation
This project is a port of the original C implementation of UUIDv47, which can be found at https://github.com/stateless-me/uuidv47.
License
MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-27