Skip to content

Commit 5bc9eb0

Browse files
Updated documentation
1 parent ddb97c1 commit 5bc9eb0

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Cycle ORM Entity Behavior Identifier
2-
[![Latest Stable Version](https://poser.pugx.org/cycle/entity-behavior-Identifier/version)](https://packagist.org/packages/cycle/entity-behavior-identifier)
2+
[![Latest Stable Version](https://poser.pugx.org/cycle/entity-behavior-identifier/version)](https://packagist.org/packages/cycle/entity-behavior-identifier)
33
[![Build Status](https://github.com/cycle/entity-behavior-identifier/workflows/build/badge.svg)](https://github.com/cycle/entity-behavior-identifier/actions)
44
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/cycle/entity-behavior-identifier/badges/quality-score.png?b=1.x)](https://scrutinizer-ci.com/g/cycle/entity-behavior-identifier/?branch=1.x)
55
[![Codecov](https://codecov.io/gh/cycle/entity-behavior-identifier/graph/badge.svg)](https://codecov.io/gh/cycle/entity-behavior)
@@ -19,9 +19,90 @@ composer require cycle/entity-behavior-identifier
1919

2020
## Snowflake Examples
2121

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.
22+
**Generic:** A flexible Snowflake format that can use a node identifier and any epoch offset, suitable for various applications requiring unique identifiers.
2323

24-
> **Note:** Support for Snowflake identifiers will arrive soon, stay tuned.
24+
```php
25+
use Cycle\Annotated\Annotation\Column;
26+
use Cycle\Annotated\Annotation\Entity;
27+
use Cycle\ORM\Entity\Behavior\Identifier;
28+
use Ramsey\Identifier\Snowflake;
29+
30+
#[Entity]
31+
#[Identifier\SnowflakeGeneric(field: 'id', node: 1, epochOffset: 1738265600000)]
32+
class User
33+
{
34+
#[Column(type: 'snowflake', primary: true)]
35+
private Snowflake $id;
36+
}
37+
```
38+
39+
**Discord:** Snowflake identifier for Discord's platform (voice, text, video), starting from epoch `2015-01-01`. Can incorporate a worker and process ID's to generate distinct Snowflakes.
40+
41+
```php
42+
use Cycle\Annotated\Annotation\Column;
43+
use Cycle\Annotated\Annotation\Entity;
44+
use Cycle\ORM\Entity\Behavior\Identifier;
45+
use Ramsey\Identifier\Snowflake;
46+
47+
#[Entity]
48+
#[Identifier\SnowflakeDiscord(field: 'id', workerId: 12, processId: 24)]
49+
class User
50+
{
51+
#[Column(type: 'snowflake', primary: true)]
52+
private Snowflake $id;
53+
}
54+
```
55+
56+
**Instagram:** Snowflake identifier for Instagram's photo and video sharing platform, with an epoch starting at `2011-08-24`. Can incorporate a shard ID to generate distinct Snowflakes.
57+
58+
```php
59+
use Cycle\Annotated\Annotation\Column;
60+
use Cycle\Annotated\Annotation\Entity;
61+
use Cycle\ORM\Entity\Behavior\Identifier;
62+
use Ramsey\Identifier\Snowflake;
63+
64+
#[Entity]
65+
#[Identifier\SnowflakeInstagram(field: 'id', shardId: 16)]
66+
class User
67+
{
68+
#[Column(type: 'snowflake', primary: true)]
69+
private Snowflake $id;
70+
}
71+
```
72+
73+
**Mastodon:** Snowflake identifier for Mastodon’s decentralized social network, generated within a database to ensure uniqueness and approximate order within 1ms. Can include a table name for distinct sequences per table; IDs are unique on a single database but not guaranteed across multiple machines.
74+
75+
```php
76+
use Cycle\Annotated\Annotation\Column;
77+
use Cycle\Annotated\Annotation\Entity;
78+
use Cycle\ORM\Entity\Behavior\Identifier;
79+
use Ramsey\Identifier\Snowflake;
80+
81+
#[Entity]
82+
#[Identifier\SnowflakeMastodon(field: 'id', tableName: 'users')]
83+
class User
84+
{
85+
#[Column(type: 'snowflake', primary: true)]
86+
private Snowflake $id;
87+
}
88+
```
89+
90+
**Twitter:** Snowflake identifier for Twitter (X), beginning from `2010-11-04`. Can incorporate a machine ID to generate distinct Snowflakes.
91+
92+
```php
93+
use Cycle\Annotated\Annotation\Column;
94+
use Cycle\Annotated\Annotation\Entity;
95+
use Cycle\ORM\Entity\Behavior\Identifier;
96+
use Ramsey\Identifier\Snowflake;
97+
98+
#[Entity]
99+
#[Identifier\SnowflakeTwitter(field: 'id', machineId: 30)]
100+
class User
101+
{
102+
#[Column(type: 'snowflake', primary: true)]
103+
private Snowflake $id;
104+
}
105+
```
25106

26107
## ULID Examples
27108

@@ -171,7 +252,7 @@ class User
171252
}
172253
```
173254

174-
You can find more information about Entity behavior UUID [here](https://cycle-orm.dev/docs/entity-behaviors-identifier).
255+
You can find more information about Entity behavior Identifier [here](https://cycle-orm.dev/docs/entity-behaviors-identifier).
175256

176257
## License:
177258

0 commit comments

Comments
 (0)