PHPackages                             unicity/unicity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. unicity/unicity

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

unicity/unicity
===============

Library to generate DB-friendly GUIDs

0.1.3(8y ago)514.3k↓48.2%MITPHPPHP &gt;=7.0

Since Feb 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Litipk/Unicity)[ Packagist](https://packagist.org/packages/unicity/unicity)[ RSS](/packages/unicity-unicity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Unicity Library
===============

[](#unicity-library)

[![Build Status](https://camo.githubusercontent.com/c38c28ad853dd68ecc49470cc27fababa2ca2348ea44be1f0bdcf8cebe0ba3a6/68747470733a2f2f7472617669732d63692e6f72672f4c697469706b2f556e69636974792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Litipk/Unicity)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/74a067830a6d8745bf6da458cdc24b556210fc431bf7a5a983562230eaf5cee6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c697469706b2f556e69636974792f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Litipk/Unicity/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/6d790fa9737c6a08cdaaef0fca078b7c2a3a54063b161e57ed3790b7bc3f6f3c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4c697469706b2f556e69636974792f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Litipk/Unicity/?branch=master)

Introduction
------------

[](#introduction)

The Unicity library serves to the purpose of generating globally unique IDs ensuring some properties:

- High (but controllable) degree of entropy/randomness:
    - Required to avoid ID guessing attacks.
- Time-related ID (with controllable precision, and proper internal representation):
    - Time-related IDs (using a proper internal representation: Big-Endian) are a good helper to preserve the natural order of insertion in our DBs.
    - In addition, using time-related IDs allows us to use B-Tree indexes without having to recreate the index with almost every insertion due to randomness.
- The possibility of representing the ID using multiple formats, including compact binary strings:
    - Base64
    - Base64 with an adaptation to be used in URLs
    - Hexadecimal
    - Binary string (the most compact form, ideal to ensure small DB indexes)

Setup
-----

[](#setup)

Install it through composer, that's it:

```
composer require unicity/unicity
```

Code examples
-------------

[](#code-examples)

### The Factory

[](#the-factory)

```
