Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

cycle/entity-behavior-identifier

 
 

Repository files navigation

Latest Stable VersionBuild StatusCodecov

The package provides the ability to useramsey/identifier as various Cycle ORM entity column types.

Installation

Note: Due to a dependency onramsey/identifier this package requires PHP8.2 or newer.

Install this package as a dependency using Composer.

composer require cycle/entity-behavior-identifier

Snowflake Examples

Generic

A flexible Snowflake format that can use a node identifier and any epoch offset, suitable for various applications requiring unique identifiers. Default values fornode andepochOffset can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\SnowflakeGeneric::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Snowflake;#[Entity]#[Identifier\SnowflakeGeneric(field:'id', node:1, epochOffset:1738265600000)]class User{    #[Column(type:'snowflake', primary:true)]privateSnowflake$id;}

Discord

Snowflake identifier for Discord's platform (voice, text, video), starting from epoch2015-01-01. Can incorporate a worker and process ID's to generate distinct Snowflakes. Default values forworkerId andprocessId can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\SnowflakeDiscord::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Snowflake;#[Entity]#[Identifier\SnowflakeDiscord(field:'id', workerId:12, processId:24)]class User{    #[Column(type:'snowflake', primary:true)]privateSnowflake$id;}

Instagram

Snowflake identifier for Instagram's photo and video sharing platform, with an epoch starting at2011-08-24. Can incorporate a shard ID to generate distinct Snowflakes. Default values forshardId can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\SnowflakeInstagram::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Snowflake;#[Entity]#[Identifier\SnowflakeInstagram(field:'id', shardId:16)]class User{    #[Column(type:'snowflake', primary:true)]privateSnowflake$id;}

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. Default values fortableName can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\SnowflakeMastodon::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Snowflake;#[Entity]#[Identifier\SnowflakeMastodon(field:'id', tableName:'users')]class User{    #[Column(type:'snowflake', primary:true)]privateSnowflake$id;}

Twitter

Snowflake identifier for Twitter (X), beginning from2010-11-04. Can incorporate a machine ID to generate distinct Snowflakes. Default values formachineId can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\SnowflakeTwitter::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Snowflake;#[Entity]#[Identifier\SnowflakeTwitter(field:'id', machineId:30)]class User{    #[Column(type:'snowflake', primary:true)]privateSnowflake$id;}

ULID Examples

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.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Ulid;#[Entity]#[Identifier\Ulid(field:'id')]class User{    #[Column(type:'ulid', primary:true)]privateUlid$id;}

UUID Examples

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. Default values fornode andclockSeq can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\Uuid1::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid1(field:'id')]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

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. Default values forlocalDomain,localIdentifier,node andclockSeq can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\Uuid2::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid2(field:'id')]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

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.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid3(    field:'id',    namespace:'6ba7b810-9dad-11d1-80b4-00c04fd430c8',    name:'example.com',)]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

UUID Version 4 (Random)

Generated entirely from random or pseudo-random numbers, offering high unpredictability and uniqueness.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid4(field:'id')]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

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.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid5(    field:'id',    namespace:'6ba7b810-9dad-11d1-80b4-00c04fd430c8',    name:'example.com',)]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

UUID Version 6 (Draft/Upcoming)

An experimental or proposed version focused on improving time-based UUIDs with more sortable properties (not yet widely adopted). Default values fornode andclockSeq can be defined globally via the\Cycle\ORM\Entity\Behavior\Identifier\Listener\Uuid6::setDefaults() method.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid6(field:'id')]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

UUID Version 7 (Draft/Upcoming)

A newer proposal designed to incorporate sortable features based on Unix timestamp, enhancing performance in database indexing.

useCycle\Annotated\Annotation\Column;useCycle\Annotated\Annotation\Entity;useCycle\ORM\Entity\Behavior\Identifier;useRamsey\Identifier\Uuid;#[Entity]#[Identifier\Uuid7(field:'id')]class User{    #[Column(type:'uuid', primary:true)]privateUuid$id;}

Global Configuration

Some listener classes provide static functions allowing you to define global default values for various attributes. This approach helps you to:

  • Initialize defaults at a suitable point in your application's lifecycle.
  • Customize defaults dynamically based on environment-specific conditions.
  • Minimize redundancy by setting shared attribute values once, instead of repeatedly specifying them across entities.

Sample code:

useCycle\ORM\Entity\Behavior\Identifier\Listener;Listener\SnowflakeGeneric::setDefaults($node,$epochOffset);Listener\SnowflakeDiscord::setDefaults($workerId,$processId);Listener\SnowflakeInstagram::setDefaults($shardId);Listener\SnowflakeMastodon::setDefaults($tableName);Listener\SnowflakeTwitter::setDefaults($machineId);Listener\Uuid1::setDefaults($node,$clockSeq);Listener\Uuid2::setDefaults($localDomain,$localIdentifier,$node,$clockSeq);Listener\Uuid3::setDefaults($namespace,$name);Listener\Uuid5::setDefaults($namespace,$name);Listener\Uuid6::setDefaults($node,$clockSeq);

You can find more information about Entity behavior Identifierhere.

License:

The MIT License (MIT). Please seeLICENSE for more information.Maintained bySpiral Scout.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp