定制 devuri/uuid-generator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devuri/uuid-generator

最新稳定版本:v0.0.1

Composer 安装命令:

composer require devuri/uuid-generator

包简介

A PHP package to generate UUIDs more securely and efficiently

README 文档

README

The UUIDGenerator class is a secure and efficient way to generate UUIDs (Universally Unique Identifiers) in PHP. It generates UUIDs according to the RFC 4122 standard, which ensures that the UUIDs are unique across time and space.

Installation

You can install the UUIDGenerator class using Composer. Run the following command in your terminal:

composer require devuri/uuid-generator

Alternatively, you can manually include the UUIDGenerator class in your PHP project.

Usage

To use the UUIDGenerator class, first import the class using the use keyword:

use Devuri\UUIDGenerator\UUIDGenerator;

Then, create a new instance of the UUIDGenerator class:

$uuidGenerator = new UUIDGenerator();

You can optionally specify the version and variant of the UUID you want to generate. The version determines the layout of the UUID, while the variant determines the encoding of the UUID. The default version is 4 (random), and the default variant is the RFC 4122 variant.

$uuidGenerator = new UUIDGenerator(1, 0x80);

To generate a new UUID, call the generateUUID() method:

$uuid = $uuidGenerator->generateUUID();

The generateUUID() method returns a string in the following format:

xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx

Where:

  • **x** is a hexadecimal digit (0-9, a-f)
  • **M** is the version number (1-5)
  • N is the variant number (8, 9, a, b)

Example

Here's an example of how to use the UUIDGenerator class to generate a new UUID:

    use Devuri\UUIDGenerator\UUIDGenerator;
    
    $uuidGenerator = new UUIDGenerator();
    $uuid = $uuidGenerator->generateUUID();
    
    echo $uuid;

This code creates a new instance of the UUIDGenerator class, generates a new UUID, and then prints the UUID to the screen.

Security

The UUIDGenerator class uses a secure and efficient method to generate UUIDs. It generates random bytes using the random_bytes() function, which is a cryptographically secure random number generator. It then sets the version and variant bits according to the RFC 4122 standard.

License

The UUIDGenerator class is open-source software licensed under the MIT License. See the LICENSE file for more information.

统计信息

  • 总下载量: 35.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-04