Download the PHP package limanweb/uuid without Composer
On this page you can find all versions of the php package limanweb/uuid. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download limanweb/uuid
More information about limanweb/uuid
Files in limanweb/uuid
Informations about the package uuid
limanweb/uuid
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 timestampU
- 5 hex digits is microseconds value of UUID generating timestampA
- 3 hex digits is custom application codeE
- 4 hex digits is custom entity codeR
- 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:
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:
getUuidAppCode()
Syntax:
getUuidAppCode(string $uuid) : int
Retrieve application code from UUID generated by genUuid()
.
Params:
$uuid
- analyzed UUID;
Example:
getUuidAppCode()
Syntax:
getUuidAppCode(string $uuid) : int
Retrieve application code from UUID generated by genUuid()
.
Params:
$uuid
- analyzed UUID;
Example:
Using trait UsesUuid
-
Add trait
\Limanweb\Uuid\Models\Concerns\UsesUuids
use declaration into models where primary key is UUID. - You can define
$appCode
and$entityCode
protected properties in your model to generate model UUID-key with specific segments.
This trait
- overrides
getIncrementing()
andgetKeyType()
methods therefore you don't need to define properties$incrementing
and$keyType
; - adds
getAppCode()
andgetEntityCode()
public methods; - registers creating event handler to generate UUID and fill model key.
Example:
All IDs generated for this model will match the pattern ########-####-#010-0100-############
.