You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+142-8Lines changed: 142 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,165 @@ The package provides the ability to use `ramsey/identifier` as various Cycle ORM
9
9
10
10
## Installation
11
11
12
-
> Notethis package required PHP `8.2` or newer.
12
+
> **Note:** Due to a dependency on `ramsey/identifier`this package requires PHP `8.2` or newer.
13
13
14
14
Install this package as a dependency using Composer.
15
15
16
16
```bash
17
17
composer require cycle/entity-behavior-identifier
18
18
```
19
19
20
-
## Example
20
+
## Snowflake Examples
21
21
22
-
They are randomly-generated and do not contain any information about the time they are created or the machine that
23
-
generated them.
22
+
**Snowflake:** A distributed ID generation system developed by Twitter that produces 64-bit unique, sortable identifiers. Each ID encodes a timestamp, machine ID, and sequence number, enabling high-throughput, ordered ID creation suitable for large-scale distributed applications.
23
+
24
+
> **Note:** Support for Snowflake identifiers will arrive soon, stay tuned.
25
+
26
+
## ULID Examples
27
+
28
+
**ULID (Universally Unique Lexicographically Sortable Identifier):** A 128-bit identifier designed for high uniqueness and lexicographical sortability. It combines a timestamp component with random data, allowing for ordered IDs that can be generated rapidly and are human-readable, making it ideal for databases and distributed systems.
29
+
30
+
```php
31
+
use Cycle\Annotated\Annotation\Column;
32
+
use Cycle\Annotated\Annotation\Entity;
33
+
use Cycle\ORM\Entity\Behavior\Identifier;
34
+
use Ramsey\Identifier\Ulid;
35
+
36
+
#[Entity]
37
+
#[Identifier\Ulid(field: 'id')]
38
+
class User
39
+
{
40
+
#[Column(type: 'ulid', primary: true)]
41
+
private Ulid $id;
42
+
}
43
+
```
44
+
45
+
## UUID Examples
46
+
47
+
**UUID Version 1 (Time-based):** Generated using the current timestamp and the MAC address of the computer, ensuring unique identification based on time and hardware.
48
+
49
+
```php
50
+
use Cycle\Annotated\Annotation\Column;
51
+
use Cycle\Annotated\Annotation\Entity;
52
+
use Cycle\ORM\Entity\Behavior\Identifier;
53
+
use Ramsey\Identifier\Uuid;
54
+
55
+
#[Entity]
56
+
#[Identifier\Uuid1(field: 'id')]
57
+
class User
58
+
{
59
+
#[Column(type: 'uuid', primary: true)]
60
+
private Uuid $id;
61
+
}
62
+
```
63
+
64
+
**UUID Version 2 (DCE Security):** Similar to version 1 but includes a local identifier such as a user ID or group ID, primarily used in DCE security contexts.
65
+
66
+
```php
67
+
use Cycle\Annotated\Annotation\Column;
68
+
use Cycle\Annotated\Annotation\Entity;
69
+
use Cycle\ORM\Entity\Behavior\Identifier;
70
+
use Ramsey\Identifier\Uuid;
71
+
72
+
#[Entity]
73
+
#[Identifier\Uuid2(field: 'id')]
74
+
class User
75
+
{
76
+
#[Column(type: 'uuid', primary: true)]
77
+
private Uuid $id;
78
+
}
79
+
```
80
+
81
+
**UUID Version 3 (Name-based, MD5):** Created by hashing a namespace identifier and name using MD5, resulting in a deterministic UUID based on input data.
**UUID Version 4 (Random):** Generated entirely from random or pseudo-random numbers, offering high unpredictability and uniqueness.
103
+
104
+
```php
105
+
use Cycle\Annotated\Annotation\Column;
106
+
use Cycle\Annotated\Annotation\Entity;
107
+
use Cycle\ORM\Entity\Behavior\Identifier;
108
+
use Ramsey\Identifier\Uuid;
109
+
110
+
#[Entity]
111
+
#[Identifier\Uuid4(field: 'id')]
112
+
class User
113
+
{
114
+
#[Column(type: 'uuid', primary: true)]
115
+
private Uuid $id;
116
+
}
117
+
```
118
+
119
+
**UUID Version 5 (Name-based, SHA-1):** Similar to version 3 but uses SHA-1 hashing, providing a different deterministic UUID based on namespace and name.
**UUID Version 6 (Draft/Upcoming):** An experimental or proposed version focused on improving time-based UUIDs with more sortable properties (not yet widely adopted).
141
+
142
+
```php
143
+
use Cycle\Annotated\Annotation\Column;
144
+
use Cycle\Annotated\Annotation\Entity;
145
+
use Cycle\ORM\Entity\Behavior\Identifier;
146
+
use Ramsey\Identifier\Uuid;
147
+
148
+
#[Entity]
149
+
#[Identifier\Uuid6(field: 'id')]
150
+
class User
151
+
{
152
+
#[Column(type: 'uuid', primary: true)]
153
+
private Uuid $id;
154
+
}
155
+
```
156
+
157
+
**UUID Version 7 (Draft/Upcoming):** A newer proposal designed to incorporate sortable features based on Unix timestamp, enhancing performance in database indexing.
0 commit comments