Skip to content

Commit 7914a72

Browse files
Updated documentation
1 parent 6ab9cfe commit 7914a72

File tree

1 file changed

+142
-8
lines changed

1 file changed

+142
-8
lines changed

README.md

Lines changed: 142 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,165 @@ The package provides the ability to use `ramsey/identifier` as various Cycle ORM
99

1010
## Installation
1111

12-
> Note this package required PHP `8.2` or newer.
12+
> **Note:** Due to a dependency on `ramsey/identifier` this package requires PHP `8.2` or newer.
1313
1414
Install this package as a dependency using Composer.
1515

1616
```bash
1717
composer require cycle/entity-behavior-identifier
1818
```
1919

20-
## Example
20+
## Snowflake Examples
2121

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.
82+
83+
```php
84+
use Cycle\Annotated\Annotation\Column;
85+
use Cycle\Annotated\Annotation\Entity;
86+
use Cycle\ORM\Entity\Behavior\Identifier;
87+
use Ramsey\Identifier\Uuid;
88+
89+
#[Entity]
90+
#[Identifier\Uuid3(
91+
field: 'id',
92+
namespace: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
93+
name: 'example.com',
94+
)]
95+
class User
96+
{
97+
#[Column(type: 'uuid', primary: true)]
98+
private Uuid $id;
99+
}
100+
```
101+
102+
**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.
120+
121+
```php
122+
use Cycle\Annotated\Annotation\Column;
123+
use Cycle\Annotated\Annotation\Entity;
124+
use Cycle\ORM\Entity\Behavior\Identifier;
125+
use Ramsey\Identifier\Uuid;
126+
127+
#[Entity]
128+
#[Identifier\Uuid5(
129+
field: 'id',
130+
namespace: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
131+
name: 'example.com',
132+
)]
133+
class User
134+
{
135+
#[Column(type: 'uuid', primary: true)]
136+
private Uuid $id;
137+
}
138+
```
139+
140+
**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.
24158

25159
```php
26160
use Cycle\Annotated\Annotation\Column;
27161
use Cycle\Annotated\Annotation\Entity;
28-
use Cycle\ORM\Entity\Behavior\Idetifier\Uuid4;
162+
use Cycle\ORM\Entity\Behavior\Identifier;
29163
use Ramsey\Identifier\Uuid;
30164

31165
#[Entity]
32-
#[Uuid4]
166+
#[Identifier\Uuid7(field: 'id')]
33167
class User
34168
{
35-
#[Column(field: 'uuid', type: 'uuid', primary: true)]
36-
private Uuid $uuid;
169+
#[Column(type: 'uuid', primary: true)]
170+
private Uuid $id;
37171
}
38172
```
39173

0 commit comments

Comments
 (0)