From 9e30c6b6f8c33b531baa62aff28c6db46f65b19e Mon Sep 17 00:00:00 2001 From: "A. B. M. Mahmudul Hasan" Date: Thu, 23 Apr 2026 16:34:43 +0600 Subject: [PATCH] updated docs --- README.md | 424 ++++----------------------------- docs/_static/theme.css | 3 + docs/compatibility-matrix.md | 27 --- docs/compatibility.rst | 34 +++ docs/conf.py | 60 +++++ docs/db-storage.md | 24 -- docs/db-storage.rst | 44 ++++ docs/exceptions.rst | 31 +++ docs/framework-integration.md | 21 -- docs/framework-integration.rst | 40 ++++ docs/helpers.rst | 80 +++++++ docs/id-facade.rst | 66 +++++ docs/index.rst | 47 ++++ docs/installation.rst | 41 ++++ docs/quickstart.rst | 73 ++++++ docs/random-ids.rst | 101 ++++++++ docs/references.rst | 19 ++ docs/requirements.txt | 7 + docs/sequence-providers.rst | 83 +++++++ docs/snowflake.rst | 96 ++++++++ docs/sonyflake.rst | 84 +++++++ docs/tbsl.rst | 76 ++++++ docs/ulid.rst | 51 ++++ docs/uuid.rst | 109 +++++++++ docs/value-objects.rst | 60 +++++ 25 files changed, 1250 insertions(+), 451 deletions(-) create mode 100644 docs/_static/theme.css delete mode 100644 docs/compatibility-matrix.md create mode 100644 docs/compatibility.rst create mode 100644 docs/conf.py delete mode 100644 docs/db-storage.md create mode 100644 docs/db-storage.rst create mode 100644 docs/exceptions.rst delete mode 100644 docs/framework-integration.md create mode 100644 docs/framework-integration.rst create mode 100644 docs/helpers.rst create mode 100644 docs/id-facade.rst create mode 100644 docs/index.rst create mode 100644 docs/installation.rst create mode 100644 docs/quickstart.rst create mode 100644 docs/random-ids.rst create mode 100644 docs/references.rst create mode 100644 docs/requirements.txt create mode 100644 docs/sequence-providers.rst create mode 100644 docs/snowflake.rst create mode 100644 docs/sonyflake.rst create mode 100644 docs/tbsl.rst create mode 100644 docs/ulid.rst create mode 100644 docs/uuid.rst create mode 100644 docs/value-objects.rst diff --git a/README.md b/README.md index 569320e..7b817e7 100644 --- a/README.md +++ b/README.md @@ -1,411 +1,77 @@ # UID -[![build](https://github.com/infocyph/UID/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/infocyph/UID/actions/workflows/build.yml) -[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cec4c7ed0e274b3da4571973732a363e)](https://app.codacy.com/gh/infocyph/UID/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) -![Packagist Downloads](https://img.shields.io/packagist/dt/infocyph/uid) +[![Security & Standards](https://github.com/infocyph/UID/actions/workflows/build.yml/badge.svg)](https://github.com/infocyph/UID/actions/workflows/build.yml) +[![Documentation](https://img.shields.io/badge/Documentation-UID-blue?logo=readthedocs&logoColor=white)](https://docs.infocyph.com/projects/UID/) +![Packagist Downloads](https://img.shields.io/packagist/dt/infocyph/UID?color=green&link=https%3A%2F%2Fpackagist.org%2Fpackages%2Finfocyph%2FUID) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) -![Packagist Version](https://img.shields.io/packagist/v/infocyph/uid) -![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/infocyph/uid) -![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/infocyph/uid) -[![]()](https://visitor-badge.laobi.icu/badge?page_id=infocyph.com) +![Packagist Version](https://img.shields.io/packagist/v/infocyph/UID) +![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/infocyph/UID/php) +![GitHub Code Size](https://img.shields.io/github/languages/code-size/infocyph/UID) -An AIO Unique ID generator written in PHP. Supports (references available at the bottom), +All-in-one unique ID toolkit for PHP. -- UUID -- ULID -- Snowflake ID -- Sonyflake ID -- TBSL -- NanoId -- Cuid2 +## Features -## Table of contents +- UUID (`v1`, `v3`, `v4`, `v5`, `v6`, `v7`, `v8`) +- ULID (monotonic and random modes) +- Snowflake, Sonyflake, TBSL +- NanoID, CUID2, KSUID, XID +- Opaque and deterministic IDs +- Value objects and comparator utilities +- Binary conversion and base encoders (`16`, `32`, `36`, `58`, `62`) +- Pluggable sequence providers (filesystem, memory, PSR-16 cache, callback) - +## Requirements -* [Prerequisites](#prerequisites) -* [Installation](#installation) -* [Usage](#usage) - * [UUID](#uuid-universal-unique-identifier) - * [UUID v1](#uuid-v1-time-based-uuid) - * [UUID v3](#uuid-v3-namespace-based-uuid) - * [UUID v4](#uuid-v4-random-uuid) - * [UUID v5](#uuid-v5-namespace-based-uuid) - * [UUID v6](#uuid-v6-draft-basedunofficial-time-based-uuid) - * [UUID v7](#uuid-v7-draft-basedunofficial-time-based-uuid) - * [UUID v8](#uuid-v8-draft-basedunofficial-time-based-uuid-lexicographically-sortable) - * [GUID](#guid) - * [Additional](#additional) - * [ULID](#ulid-universally-unique-lexicographically-sortable-identifier) - * [Snowflake ID](#snowflake-id) - * [Sonyflake ID](#sonyflake-id) - * [TBSL ID](#tbsl-time-based-keys-with-lexicographic-sorting-library-exclusive) - * [RandomId](#randomid) - * [NanoId](#nanoid-url-friendly-unique-random-id) - * [Cuid2](#cuid2-url-friendly-secure--collision-free) -* [Benchmark](#benchmark) -* [Support](#support) -* [References](#references) - - - -## Prerequisites - -Language: PHP 8.2+ +- PHP `>=8.2` +- `ext-bcmath` ## Installation -``` +```bash composer require infocyph/uid ``` -Global helper functions are available via Composer autoload. - -## Usage - -### UUID (Universal Unique Identifier) - -The node specific UUID's `$node` parameter (1, 6, 7, 8) is optional. If not provided, it will be generated randomly. -But, if you wanna track the source of the UUIDs, you should use it (pre-define the node per server & pass it -accordingly). - -#### UUID v1: Time-based UUID. - -- Generate v1 UUID - -```php -// Get v1 UUID -\Infocyph\UID\UUID::v1(); -// alternatively can also use -uuid1(); -``` - -- Pass your pre-generated node (for node specific UUID) - -```php -\Infocyph\UID\UUID::v1($node); // check additional section for how to generate one -``` - -#### UUID v3: Namespace based UUID. - -- Generate v3 UUID - -```php -// Get v3 UUID -\Infocyph\UID\UUID::v3('a pre-generated UUID', 'the string you wanna get UUID for'); -// alternatively can also use -uuid3(); -``` - -- Get v3 UUID for predefined namespaces (RFC4122 #Appendix C) - -```php -/** -* You can pass X500, URL, OID, DNS (check RFC4122 #Appendix C) -*/ -\Infocyph\UID\UUID::v3('url', 'abmmhasan.github.io'); -``` - -- You can generate a UUID & use as namespace as well - -```php -\Infocyph\UID\UUID::v3('fa1700dd-828c-4d1b-8e6d-a6104807da90', 'abmmhasan.github.io'); -``` - -#### UUID v4: Random UUID. - -- Generate v4 UUID - -```php -// Get v4 UUID (completely random) -\Infocyph\UID\UUID::v4(); -// alternatively can also use -uuid4(); -``` - -#### UUID v5: Namespace based UUID. - -- Generate v5 UUID - -```php -// Get v5 UUID -\Infocyph\UID\UUID::v5('a pre-generated UUID', 'the string you wanna get UUID for'); -// alternatively can also use -uuid5(); -``` - -- Get v5 UUID for predefined namespaces (RFC4122 #Appendix C) - -```php -/** -* You can pass X500, URL, OID, DNS (check RFC4122 #Appendix C) -*/ -\Infocyph\UID\UUID::v5('url', 'abmmhasan.github.io'); -``` - -- You can generate a UUID & use as namespace as well - -```php -UUID::v5('fa1700dd-828c-4d1b-8e6d-a6104807da90', 'abmmhasan.github.io'); -``` - -#### UUID v6 (draft-based/unofficial): Time-based UUID. - -- Generate v6 UUID - -```php -// Get v6 UUID (Time based) -\Infocyph\UID\UUID::v6(); -// alternatively can also use -uuid6(); -``` - -- Get v6 UUID using predefined node: - -```php -\Infocyph\UID\UUID::v6($node); // check additional section for how to generate one -``` - -#### UUID v7 (draft-based/unofficial): Time-based UUID. - -- Generate v7 UUID - -```php -// Get v7 UUID for current time -\Infocyph\UID\UUID::v7(); -// alternatively can also use -uuid7(); -``` - -- Get v7 UUID using predefined node: - -```php -\Infocyph\UID\UUID::v7(null, $node); // check additional section for, how to generate one -``` - -- Or if you wanna get v7 UUID using predefined time: - -```php -$timeInterface = new DateTime(); // DateTime implements DateTimeInterface -\Infocyph\UID\UUID::v7($timeInterface); -``` - -- You can combine both parameters together as well. - -#### UUID v8 (draft-based/unofficial): Time-based UUID. Lexicographically sortable. - -- Generate v8 UUID - -```php -// Get v8 UUID -\Infocyph\UID\UUID::v8(); -// alternatively can also use -uuid8(); -``` - -- Get v8 UUID using predefined node: - -```php -\Infocyph\UID\UUID::v8($node); // check additional section for, how to generate one -``` - -#### GUID - -GUID generator, works in all platform. Generate: - -```php -\Infocyph\UID\UUID::guid() -``` - -_Note: Sending false in only parameter will return the string enclosed with Braces_ +Global helper functions are autoloaded via `src/functions.php`. -#### Additional - -- Generate node for further use (with version: 1, 6, 7, 8) +## Quick Usage ```php -\Infocyph\UID\UUID::getNode(); -``` + DateTimeInterface object, sequence, worker_id, datacenter_id] -\Infocyph\UID\Snowflake::parse($snowflake); -``` - -- Specify start time for Snowflake ID (a Snowflake ID is unique upto 69 years from the start date): - -```php -// By default, the start time is set to `2020-01-01 00:00:00`, which is changeable -// but if changed, this should always stay same as long as your project lives -// & must call this before any Snowflake call (generate/parse) -\Infocyph\UID\Snowflake::setStartTimeStamp('2000-01-01 00:00:00'); -``` - -### Sonyflake ID - -- Generate a new Sonyflake ID (You can also pass your pre-generated machine_id for server detection): - -```php -// Get Sonyflake ID -// optionally set machine_id, for server detection -\Infocyph\UID\Sonyflake::generate(); -// alternatively -\Infocyph\UID\sonyflake(); -``` - -- Parse Sonyflake ID (get the timestamp, sequence, machine_id): - -```php -// Parse Sonyflake ID -// returns [time => DateTimeInterface object, sequence, machine_id] -\Infocyph\UID\Sonyflake::parse($sonyflake); -``` - -- Specify start time for Sonyflake ID (a Sonyflake ID is unique upto 174 years from the start date): - -```php -// By default, the start time is set to `2020-01-01 00:00:00`, which is changeable -// but if changed, this should always stay same as long as your project lives -// & must call this before any Sonyflake call (generate/parse) -\Infocyph\UID\Sonyflake::setStartTimeStamp('2000-01-01 00:00:00'); -``` - -### TBSL: Time-Based Keys with Lexicographic Sorting (library exclusive) - -- Get TBSL ID (You can also pass your pre-generated machine_id for server detection): - -```php -// Get TBSL ID -// optionally set machine_id, for server detection -\Infocyph\UID\TBSL::generate(); -// alternatively -tbsl(); -``` - -- Parse TBSL ID (get the timestamp, machine_id): - -```php -// Parse TBSL -// returns [isValid, time => DateTimeInterface object, machine_id] -\Infocyph\UID\TBSL::parse($tbsl); -``` -- Getting unique sequence - -```php -tbsl(0, true); // send true in 2nd parameter to enable sequence -``` - -### RandomId - -With this you can generate RandomIds. These are great for usage where you don't want a large length/formatted IDs like UUID4. -These IDs are unique & can't be backtracked. - -#### NanoID (URL friendly Unique Random ID) - -- Generate - -```php -// By default, it will generate id of length 21. -// You can pass in desired length -\Infocyph\UID\RandomId::nanoId(); -``` - -#### Cuid2 (URL friendly, secure & collision free) - -- Generate - -```php -// By default, it will generate id of length 24. -// You can pass in desired length in between 4 & 32 -\Infocyph\UID\RandomId::cuid2(); -``` - -## Benchmark - -Additional hotspot benchmarks (same-ms bursts, parser speed, and provider overhead) are available in [`benchmarks/`](benchmarks/). - -| Type | Generation time (ms) | -|:---------------------------|:---------------------------------------------------------------------------------:| -| UUID v1 (random node) | 0.00411 (ramsey/Uuid: 0.18753) | -| UUID v1 (fixed node) | 0.00115 (ramsey/Uuid: 0.17386) | -| UUID v3 (custom namespace) | 0.00257 (ramsey/Uuid: 0.03015) | -| UUID v4 | 0.00362 (ramsey/Uuid: 0.16501) | -| UUID v5 (custom namespace) | 0.00108 (ramsey/Uuid: 0.03658) | -| UUID v6 (random node) | 0.00444 (ramsey/Uuid: 0.17469) | -| UUID v6 (fixed node) | 0.00164 (ramsey/Uuid: 0.17382) | -| UUID v7 (random node) | 0.00503 (ramsey/Uuid: 0.16278) | -| UUID v7 (fixed node) | 0.00154 (ramsey/Uuid: 0.18753) | -| UUID v8 (random node) | 0.00505 (ramsey/Uuid: N/A) | -| UUID v8 (fixed node) | 0.00209 (ramsey/Uuid: 0.16029 _*predefined random node, not usable as signature_) | -| ULID | 0.00506 (robinvdvleuten/php-ulid: 0.00508) | -| Snowflake | 0.13951 (godruoyi/php-snowflake: 0.14856) | -| Sonyflake | 0.13821 (godruoyi/php-snowflake: 0.14583) | -| TBSL | 0.0034 | -| NanoID | 0.00057 | -| Cuid2 | 0.01817 | - -## Support - -Having trouble? Create an issue! - ## References -- UUID (RFC4122/RFC9562): https://datatracker.ietf.org/doc/html/rfc9562 +- UUID: https://datatracker.ietf.org/doc/html/rfc9562 - ULID: https://github.com/ulid/spec -- Snowflake ID: https://github.com/twitter-archive/snowflake/tree/snowflake-2010 -- Sonyflake ID: https://github.com/sony/sonyflake -- TBSL ID: https://github.com/infocyph/UID/blob/main/TBSL.md +- Snowflake: https://github.com/twitter-archive/snowflake/tree/snowflake-2010 +- Sonyflake: https://github.com/sony/sonyflake - NanoID: https://github.com/ai/nanoid -- Cuid2: https://github.com/paralleldrive/cuid2 -- Compatibility matrix: [docs/compatibility-matrix.md](docs/compatibility-matrix.md) -- DB storage notes: [docs/db-storage.md](docs/db-storage.md) -- Framework integration notes: [docs/framework-integration.md](docs/framework-integration.md) +- CUID2: https://github.com/paralleldrive/cuid2 +- TBSL note: https://github.com/infocyph/UID/blob/main/TBSL.md diff --git a/docs/_static/theme.css b/docs/_static/theme.css new file mode 100644 index 0000000..ae81ea7 --- /dev/null +++ b/docs/_static/theme.css @@ -0,0 +1,3 @@ +.highlight-php .k { + color: #0077aa; /* Example: make PHP keywords a different color */ +} diff --git a/docs/compatibility-matrix.md b/docs/compatibility-matrix.md deleted file mode 100644 index 21ab268..0000000 --- a/docs/compatibility-matrix.md +++ /dev/null @@ -1,27 +0,0 @@ -# Compatibility Matrix - -## UUID support - -- `v1`, `v3`, `v4`, `v5`: RFC 4122 / RFC 9562 compatible layouts. -- `v6`, `v7`: RFC 9562 time-ordered UUIDs. -- `v8`: custom payload strategy inside RFC 9562 v8 envelope. -- `guid()`: Microsoft-compatible GUID text formatting helper. - -## Non-UUID families - -- `ULID`: Crockford base32 ULID (monotonic + random generation modes). -- `Snowflake`: 64-bit Twitter-style ID (41/5/5/12 layout). -- `Sonyflake`: 64-bit Sonyflake-style ID (39/16/8 layout). -- `TBSL`: project-specific time-based sortable hex identifier. -- `NanoID`, `CUID2`: random ID families for URL-safe usage. - -## Binary and alternate representations - -- UUID / ULID / TBSL: `toBytes()` / `fromBytes()`. -- UUID / ULID / TBSL / Snowflake / Sonyflake: base encodings via `toBase()` / `fromBase()` where applicable. - -## Runtime - -- Minimum PHP: `8.2`. -- Required extension: `ext-bcmath`. -- Optional sequence backends: filesystem (default), in-memory, PSR-16 simple cache, callback. diff --git a/docs/compatibility.rst b/docs/compatibility.rst new file mode 100644 index 0000000..e206b3c --- /dev/null +++ b/docs/compatibility.rst @@ -0,0 +1,34 @@ +Compatibility Matrix +==================== + +UUID Support +------------ + +- ``v1``, ``v3``, ``v4``, ``v5``: RFC 4122 / RFC 9562 compatible layouts. +- ``v6``, ``v7``: RFC 9562 time-ordered UUIDs. +- ``v8``: custom payload strategy inside UUID v8 envelope. +- ``guid()``: Microsoft-compatible GUID text formatting helper. + +Non-UUID Families +----------------- + +- ULID: Crockford Base32 ULID with monotonic and random modes. +- Snowflake: 64-bit Twitter-style ID (41/5/5/12). +- Sonyflake: 64-bit Sonyflake-style ID (39/16/8). +- TBSL: project-specific time-based sortable hex identifier. +- NanoID and CUID2: URL-safe random IDs. +- KSUID and XID: sortable short ID families. + +Binary and Alternate Encodings +------------------------------ + +- UUID / ULID / TBSL: ``toBytes()`` / ``fromBytes()``. +- UUID / ULID / Snowflake / Sonyflake / TBSL: ``toBase()`` / ``fromBase()``. +- KSUID / XID: ``toBytes()`` / ``fromBytes()``. + +Runtime Requirements +-------------------- + +- Minimum PHP: ``8.2`` +- Required extension: ``ext-bcmath`` +- Optional sequence backends: filesystem, in-memory, PSR-16 cache, callback. diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..878090b --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,60 @@ +from __future__ import annotations + +import datetime +import os + +project = "UID" +author = "Infocyph" +year_now = datetime.date.today().strftime("%Y") +copyright = f"2024-{year_now}" +version = os.environ.get("READTHEDOCS_VERSION", "latest") +release = version +language = "en" +root_doc = "index" + +extensions = [ + "myst_parser", + "sphinx.ext.todo", + "sphinx.ext.autosectionlabel", + "sphinx.ext.intersphinx", + "sphinx_copybutton", + "sphinx_design", + "sphinxcontrib.phpdomain", +] + +myst_enable_extensions = [ + "colon_fence", + "deflist", + "attrs_block", + "attrs_inline", + "tasklist", + "fieldlist", +] + +myst_heading_anchors = 3 +autosectionlabel_prefix_document = True +todo_include_todos = True + +intersphinx_mapping = { + "php": ("https://www.php.net/manual/en/", None), +} + +html_theme = "sphinx_book_theme" +html_theme_options = { + "repository_url": "https://github.com/infocyph/UID", + "repository_branch": "main", + "path_to_docs": "docs", + "use_repository_button": True, + "use_issues_button": True, + "use_download_button": True, + "home_page_in_toc": True, + "show_toc_level": 2, +} + +templates_path = ["_templates"] +html_static_path = ["_static"] +html_css_files = ["theme.css"] +html_title = f"UID - {version} Documentation" +html_show_sourcelink = True +html_show_sphinx = False +html_last_updated_fmt = "%Y-%m-%d" diff --git a/docs/db-storage.md b/docs/db-storage.md deleted file mode 100644 index 789d5c5..0000000 --- a/docs/db-storage.md +++ /dev/null @@ -1,24 +0,0 @@ -# Sortable DB Helpers - -## UUID - -- MySQL: prefer `BINARY(16)` for compact indexes. -- PostgreSQL: prefer native `UUID` type. -- Ordering: use UUIDv7 when insertion locality matters. - -## ULID - -- MySQL: `CHAR(26)` (human-friendly) or `BINARY(16)` (compact). -- PostgreSQL: `CHAR(26)` or `BYTEA`. -- Ordering: canonical ULID text preserves chronological order. - -## Snowflake / Sonyflake - -- MySQL: `BIGINT UNSIGNED`. -- PostgreSQL: `BIGINT` if in range, otherwise `NUMERIC(20,0)`. -- Ordering: numeric sort is time sort. - -## TBSL - -- Store as fixed-length uppercase hex: `CHAR(20)`. -- If compactness matters, store bytes in `BINARY(10)` via `toBytes()`. diff --git a/docs/db-storage.rst b/docs/db-storage.rst new file mode 100644 index 0000000..e5b2ebd --- /dev/null +++ b/docs/db-storage.rst @@ -0,0 +1,44 @@ +Database Storage +================ + +UID includes ``Infocyph\\UID\\DbStorage`` with recommendations for UUID, ULID, and Snowflake. + +UUID +---- + +- MySQL: prefer ``BINARY(16)`` for compact indexes. +- PostgreSQL: prefer native ``UUID`` type. +- Ordering: ``UUIDv7`` provides better insertion locality than ``UUIDv4``. + +ULID +---- + +- MySQL: ``CHAR(26)`` (readable) or ``BINARY(16)`` (compact/index-friendly). +- PostgreSQL: ``CHAR(26)`` or ``BYTEA`` depending on interoperability. +- Ordering: canonical ULID text is chronologically sortable. + +Snowflake and Sonyflake +----------------------- + +- MySQL: ``BIGINT UNSIGNED``. +- PostgreSQL: ``BIGINT`` if range is safe, otherwise ``NUMERIC(20,0)``. +- Ordering: numeric sort equals time sort. + +TBSL +---- + +- Use ``CHAR(20)`` for canonical uppercase hex. +- Use ``BINARY(10)`` when compactness matters. + +Programmatic Access +------------------- + +.. code-block:: php + + isSortable(); diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..989fee3 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,47 @@ +UID Documentation +================= + +UID is an all-in-one ID toolkit for PHP with generation, parsing, validation, and conversion APIs. + +It supports: + +- UUID (v1, v3, v4, v5, v6, v7, v8) +- ULID +- Snowflake +- Sonyflake +- TBSL +- NanoID and CUID2 +- KSUID and XID +- Opaque and deterministic IDs + +.. toctree:: + :maxdepth: 2 + :caption: Getting Started + + installation + quickstart + id-facade + +.. toctree:: + :maxdepth: 2 + :caption: Generators + + uuid + ulid + snowflake + sonyflake + tbsl + random-ids + +.. toctree:: + :maxdepth: 2 + :caption: Advanced + + sequence-providers + value-objects + helpers + db-storage + compatibility + framework-integration + exceptions + references diff --git a/docs/installation.rst b/docs/installation.rst new file mode 100644 index 0000000..8575c2f --- /dev/null +++ b/docs/installation.rst @@ -0,0 +1,41 @@ +Installation +============ + +Requirements +------------ + +- PHP ``>=8.2`` +- ``ext-bcmath`` +- Composer + +Install +------- + +.. code-block:: bash + + composer require infocyph/uid + +Autoloaded Helpers +------------------ + +UID ships global helper functions via Composer autoload from ``src/functions.php``. + +If you prefer explicit static APIs only, call the namespaced classes directly: + +- ``Infocyph\\UID\\Id`` +- ``Infocyph\\UID\\UUID`` +- ``Infocyph\\UID\\ULID`` +- ``Infocyph\\UID\\Snowflake`` +- ``Infocyph\\UID\\Sonyflake`` +- ``Infocyph\\UID\\TBSL`` + +Read the Docs Build +------------------- + +This repository already includes: + +- ``docs/conf.py`` +- ``docs/requirements.txt`` +- ``.readthedocs.yaml`` + +So you can publish directly on Read the Docs without extra Sphinx bootstrapping. diff --git a/docs/quickstart.rst b/docs/quickstart.rst new file mode 100644 index 0000000..9fe18c9 --- /dev/null +++ b/docs/quickstart.rst @@ -0,0 +1,73 @@ +Quickstart +========== + +Using the ``Id`` Facade +----------------------- + +.. code-block:: php + + =8.0,<9 +myst-parser>=2.0 +sphinx-book-theme>=1.1 +sphinxcontrib-phpdomain>=0.9 +sphinx-copybutton>=0.5.2 +sphinx-design>=0.6 +linkify-it-py>=2.0 diff --git a/docs/sequence-providers.rst b/docs/sequence-providers.rst new file mode 100644 index 0000000..c8d8f52 --- /dev/null +++ b/docs/sequence-providers.rst @@ -0,0 +1,83 @@ +Sequence Providers +================== + +UID supports pluggable sequence backends for Snowflake, Sonyflake, and sequenced TBSL. + +Supported Providers +------------------- + +- ``FilesystemSequenceProvider`` (default) +- ``InMemorySequenceProvider`` +- ``PsrSimpleCacheSequenceProvider`` +- ``CallbackSequenceProvider`` +- Any custom ``SequenceProviderInterface`` implementation + +Per-Algorithm Static Selection +------------------------------ + +Each algorithm class using ``GetSequence`` provides these static methods: + +- ``setSequenceProvider(SequenceProviderInterface $provider)`` +- ``resetSequenceProvider()`` +- ``useFilesystemSequenceProvider(?string $baseDirectory = null, int $waitTime = 100, int $maxAttempts = 10)`` +- ``useInMemorySequenceProvider()`` +- ``useSimpleCacheSequenceProvider(CacheInterface $cache, string $prefix = 'uid:seq:', int $waitTime = 100, int $maxAttempts = 10)`` +- ``useSequenceCallback(callable $callback)`` + +Example: Process-Local In-Memory +-------------------------------- + +.. code-block:: php + + toString(); + $uuidVersion = $uuid->getVersion(); + $uuidTime = $uuid->getTimestamp(); + +IdComparator +------------ + +``Infocyph\\UID\\IdComparator`` provides generic comparison/sorting: + +- ``compare(IdValueInterface|string $left, IdValueInterface|string $right): int`` +- ``sort(array $ids): array`` + +When both values are digit-only, comparator uses unsigned-decimal ordering; +otherwise it falls back to lexical comparison. + +.. code-block:: php + +