pixielity/laravel-uuid
Composer 安装命令:
composer require pixielity/laravel-uuid
包简介
UUID generation and management utilities
README 文档
README
The UUID Module provides a robust and flexible API for generating and managing Universally Unique Identifiers (UUIDs). It supports various UUID versions (1, 3, 4, and 5) and includes utilities for validation, namespace-based generation, and lexicographically sortable UUIDs.
Features • Generate UUIDs for versions 1, 3, 4, and 5. • Supports namespace-based UUID generation. • Generate lexicographically sortable UUIDs. • Validate UUID strings for correctness. • Custom exceptions for error handling.
Installation
To use the UUID Module, follow these steps:
- Install the package (if applicable):
composer require pixielity/laravel-framework-uuid
- Configure it in your application or register the service provider (if required).
Usage
Importing the Facade
The Uuid facade offers a convenient way to interact with the UUID Manager:
use Pixielity\Uuid\Facades\Uuid;
Available Methods
- generate(int $version, ?string $namespace = null, ?string $name = null)
Generates a UUID for the specified version. Supports versions 1, 3, 4, and 5.
// Generate a version 4 UUID $uuidV4 = Uuid::generate(4);
// Generate a version 5 UUID using a namespace and name $uuidV5 = Uuid::generate(5, 'namespace-uuid', 'resource-name');
- orderedUuid()
Generates a lexicographically sortable UUID, ideal for database indexing.
$orderedUuid = Uuid::orderedUuid();
- uuid1()
Generates a version 1 UUID based on timestamp and node.
$uuidV1 = Uuid::uuid1();
- uuid3(string $namespace, string $name)
Generates a version 3 UUID using a namespace and name (MD5 hashing).
$uuidV3 = Uuid::uuid3('namespace-uuid', 'resource-name');
- uuid4()
Generates a random version 4 UUID.
$uuidV4 = Uuid::uuid4();
- uuid5(string $namespace, string $name)
Generates a version 5 UUID using a namespace and name (SHA-1 hashing).
$uuidV5 = Uuid::uuid5('namespace-uuid', 'resource-name');
- namespaceUuid(string $namespace, string $name)
Generates a namespace-based UUID, equivalent to uuid5.
$namespaceUuid = Uuid::namespaceUuid('namespace-uuid', 'resource-name');
- isValid(string $uuid)
Validates whether a given string is a valid UUID.
$isValid = Uuid::isValid('550e8400-e29b-41d4-a716-446655440000');
Examples
Generating and Validating a UUID
use Pixielity\Uuid\Facades\Uuid;
// Generate a UUID version 4 $uuid = Uuid::uuid4(); echo "Generated UUID: $uuid";
// Validate the UUID if (Uuid::isValid($uuid)) { echo "The UUID is valid."; } else { echo "The UUID is invalid."; }
Generating a Namespace-Based UUID
$namespaceUuid = Uuid::namespaceUuid('my-namespace-uuid', 'my-resource-name'); echo "Namespace-based UUID: $namespaceUuid";
Constants
The module defines constants for common use cases: • UUID Field Name:
const UUID = 'uuid';
You can reference this constant for database schema fields or application logic.
Exceptions
All methods throw the Pixielity\Foundation\Exceptions\Exception in cases where UUID generation or validation fails. Ensure you wrap calls in try-catch blocks for error handling.
try { $uuid = Uuid::generate(6); // Invalid version } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
Contributing
- Fork the repository.
- Create a feature branch: git checkout -b feature-name.
- Commit your changes: git commit -m "Add feature description".
- Push to the branch: git push origin feature-name.
- Open a pull request for review.
License
This module is open-source software licensed under the MIT license.
Support
If you encounter any issues or have questions, feel free to open an issue in the repository or contact the support team.
pixielity/laravel-uuid 适用场景与选型建议
pixielity/laravel-uuid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「uuid」 「laravel」 「identifier」 「pixielity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pixielity/laravel-uuid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pixielity/laravel-uuid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pixielity/laravel-uuid 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Paramconverter, Normalizer and Form Type for Ramsey Uuid
A PHP library for generating and working with identifiers, including UUIDs, ULIDs, and Snowflakes
DrUUID RFC 4122 library for PHP
Trait to generate uuid when creating models
SilverStripe module for adding an unique id (UUID) to a DataObject
A CakePHP plugin for using secure, non-incremental IDs for entities
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-08