componenta/identity 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

componenta/identity

Composer 安装命令:

composer require componenta/identity

包简介

Identity contracts and immutable identities for Componenta

README 文档

README

UUID value objects and generators for domain identities.

Installation

composer require componenta/identity

The package declares Componenta\Identity\ConfigProvider in extra.componenta.config-providers. When componenta/composer-plugin is installed, the provider is added to the generated provider list automatically.

Requirements

  • PHP 8.4+
  • 64-bit PHP runtime for UuidFactory

Related Packages

Package Why it matters here
componenta/policy Uses IdentityInterface for actors and owned resources.
componenta/cqrs Operation uses UUIDs as operation identifiers.
componenta/di Registers UuidFactoryInterface through ConfigProvider.
componenta/uuid Legacy Ramsey compatibility; new domain code should prefer this package.

What It Provides

  • UuidInterface: minimal identity contract with string conversion and equality.
  • RfcUuidInterface: UUID contract with bytes, version, and variant properties.
  • Uuid: immutable RFC UUID value object backed by 16 raw bytes.
  • UuidFactoryInterface: generation/from-bytes contract.
  • UuidFactory: UUID v1, v3, v4, v5, v6, v7, and v8 generator.
  • UuidNamespace: standard namespaces for name-based UUIDs.

UUID Value Object

use Componenta\Identity\Uuid;

$uuid = Uuid::fromString('018f6d5d-3f7a-7a9b-8c2f-123456789abc');

$uuid->toString(); // 018f6d5d-3f7a-7a9b-8c2f-123456789abc
$uuid->bytes;      // 16-byte binary representation
$uuid->version;    // 7
$uuid->variant;    // UuidVariant::Rfc

Uuid::fromString() accepts uppercase input and normalizes output to lowercase canonical form.

Equality

$left = Uuid::fromString($id);
$right = Uuid::fromBytes($left->bytes);

$left->equals($right); // true

Domain code should usually depend on UuidInterface. Infrastructure that needs raw bytes or version inspection can depend on RfcUuidInterface.

UUID Factory

use Componenta\Identity\UuidFactory;
use Componenta\Identity\UuidGenerationVersion;
use Componenta\Identity\UuidNamespace;

$factory = new UuidFactory(UuidGenerationVersion::V7);

$id = $factory->generate();              // default version
$random = $factory->v4();                // random UUID
$ordered = $factory->v7();               // Unix timestamp UUID
$nameBased = $factory->v5(UuidNamespace::Dns, 'example.com');

Name-based UUIDs are deterministic for the same namespace and name.

DI Registration

ConfigProvider registers UuidFactoryInterface as a factory returning UuidFactory.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固