一个用于自动生成32位唯一整数标识符的包,这些标识符可以用作关系数据库中的主键

1.0.4 2024-01-13 13:40 UTC

This package is auto-updated.

Last update: 2024-09-13 17:43:49 UTC


README

此包的目标是

  • 提供唯一标识符。
  • 这些标识符将是整数,因此可以用作关系数据库中的主键以保持性能。
  • 不要依赖于第三方服务来生成Id,就像工人在发生时做的那样。
  • 生成的标识符将是32字节。

当前公式是

UniqueId = php-object-identifier + random-integer + microtime

为此标识符被重复时,对象标识符、微时间和7位随机整数应该一致。这实际上是非常不可能的,但在非常罕见的情况下可能发生。

使用示例

<?php

use JordiMorillo\Uid\Uid;

class MyProductId extends Uid {}

$myProductId = new MyProductId();

echo "$myProductId"; //This should cast the identifier as a string of numbers

$myProductIdString = $myProductId->toString();

$anotherProductId = new MyProductId($myProductIdString); //This should be a similar equal as $myProductId