承接 limanweb/uuid 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

limanweb/uuid

最新稳定版本:v1.1.1

Composer 安装命令:

composer require limanweb/uuid

包简介

Custom UUID generate and analyze functions

README 文档

README

Description

Package provides any functions to generate and analyze UUID.

Structure of generated UUID

There used custom algorithm to generate UUID with next structure:

SSSSSSSS-UUUU-UAAA-EEEE-RRRRRRRRRRRR
  • S - 8 hex digits is seconds value of UUID generating timestamp
  • U - 5 hex digits is microseconds value of UUID generating timestamp
  • A - 3 hex digits is custom application code
  • E - 4 hex digits is custom entity code
  • R - 12 hex digits is random value

What is entity and application codes?

You can define any integer entity code and/or application code when call genUuid(). This allows you to distinguish visually and programmatically between UUIDs created by different applications for different DB entities.

Installation

Run command to install a package into you project

composer require limanweb/uuid

Limanweb\Uuid\Support\Uuid functions

genUuid()

Syntax:

genUuid(int $entityCode = null, int $appCode = null) : string

Returns UUID-string.

Params:

  • $entityCode - custom integer code of entity (is 0 by default). Max value is 65535
  • $appCode - custom integer code of application (is 0 by default). Max value is 4095

Returns UUID string.

Example:

$uuid = \Limanweb\Uuid\Support\Uuid::genUuid(256, 16);
echo $uuid; // "5ec004c4-0db2-0010-0100-a08cc1dd9a2b"

getUuidTimestamp()

Syntax:

getUuidTimestamp(string $uuid, string $format = 'Carbon') : mixed

Retrieve timestamp from UUID generated by genUuid().

Params:

  • $uuid - analyzed UUID;
  • $format - format of returning timestamp value. You can use one of tree variants:
    • Carbon (default) to get timestamp as \Carbon\Carbon object;
    • DateTime to get timestamp as \DateTime object;
    • date format string used for format() to get timestamp as formatted string. For example: 'Y-m-d H:i:s.u'

Example:

$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$ts = \Limanweb\Uuid\Support\Uuid::getUuidTimestamp($uuid, "Y-m-d H:i:s.u");

echo $ts; // "2020-05-16 18:20:36.056096"	

getUuidAppCode()

Syntax:

getUuidAppCode(string $uuid) : int

Retrieve application code from UUID generated by genUuid().

Params:

  • $uuid - analyzed UUID;

Example:

$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$appCode = \Limanweb\Uuid\Support\Uuid::getUuidAppCode($uuid);
echo $appCode; // 16

getUuidAppCode()

Syntax:

getUuidAppCode(string $uuid) : int

Retrieve application code from UUID generated by genUuid().

Params:

  • $uuid - analyzed UUID;

Example:

$uuid = "5ec004c4-0db2-0010-0100-a08cc1dd9a2b";

$appCode = \Limanweb\Uuid\Support\Uuid::getUuidAppCode($uuid);
echo $appCode; // 256

Using trait UsesUuid

  1. Add trait \Limanweb\Uuid\Models\Concerns\UsesUuids use declaration into models where primary key is UUID.

  2. You can define $appCode and $entityCode protected properties in your model to generate model UUID-key with specific segments.

This trait

  • overrides getIncrementing() and getKeyType() methods therefore you don't need to define properties $incrementing and $keyType;
  • adds getAppCode() and getEntityCode() public methods;
  • registers creating event handler to generate UUID and fill model key.

Example:

class MyModel extends Model
{
	use \Limanweb\Uuid\Models\Concerns\UsesUuids;
	
	protected $appCode = 16;	// 010
	protected $entityCode = 256;	// 0100
	
	...

All IDs generated for this model will match the pattern ########-####-#010-0100-############.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固