PHPackages                             etel/identifier - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. etel/identifier

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

etel/identifier
===============

Represents contracts and infrastructure for identifiers.

v1.0.0(1mo ago)032MITPHPPHP ^8.4CI passing

Since Jun 6Pushed 1mo agoCompare

[ Source](https://github.com/etel-soft/identifier)[ Packagist](https://packagist.org/packages/etel/identifier)[ Docs](https://github.com/etel-soft/identifier)[ RSS](/packages/etel-identifier/feed)WikiDiscussions main Synced 1w ago

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

[![CI Status](https://github.com/etel-soft/identifier/workflows/CI/badge.svg)](https://github.com/etel-soft/identifier/actions)[![codecov](https://camo.githubusercontent.com/51496180a2ae65e301b1f2454071cb0132f1b9641f702d88cfc3bba45aefca55/68747470733a2f2f636f6465636f762e696f2f67682f6574656c2d736f66742f6964656e7469666965722f67726170682f62616467652e7376673f746f6b656e3d45434550514c50314b45)](https://codecov.io/gh/etel-soft/identifier)[![Latest Stable Version](https://camo.githubusercontent.com/7503be571275ec61560405a920856486f9fe8aa9908a40f6d7d09bc6b820f5c2/687474703a2f2f706f7365722e707567782e6f72672f6574656c2f6964656e7469666965722f76)](https://packagist.org/packages/etel/identifier)[![License](https://camo.githubusercontent.com/de3b31adfd375f511ccae67f6dc67a7b4ef9bee27aeb0887a602854b4deb3e59/687474703a2f2f706f7365722e707567782e6f72672f6574656c2f6964656e7469666965722f6c6963656e7365)](https://packagist.org/packages/etel/identifier)[![PHP Version Require](https://camo.githubusercontent.com/4033deaf00a52529b1f47d454c17466d71fab590d704a76343ce1c97a3414889/687474703a2f2f706f7365722e707567782e6f72672f6574656c2f6964656e7469666965722f726571756972652f706870)](https://packagist.org/packages/etel/identifier)

etel/identifier
===============

[](#etelidentifier)

Contracts and ready-to-use trait implementations for typed identifier value objects in PHP 8.4+.

Installation
------------

[](#installation)

```
composer require etel/identifier
```

To use UUID-based identifiers, also require `symfony/uid`:

```
composer require symfony/uid
```

Concepts
--------

[](#concepts)

An **identifier** is an immutable value object that wraps a raw value (integer, string, or UUID) and exposes it through a typed `$value` property and a string representation via `$string`.

Every identifier type carries a `PREFIX` constant used as a human-readable namespace in its string form (e.g. `usr_42`, `order_01JV3BWXYZ`). An empty prefix is valid but prevents `IdentifierResolver`from distinguishing the type by string.

Defining an identifier
----------------------

[](#defining-an-identifier)

Implement one of the sub-interfaces and use the matching trait:

**Integer identifier** (positive integers only):

```
use Etel\Identifier\IntegerIdentifier;
use Etel\Identifier\Implementation\Integer\IntegerIdentifierTrait;

final class UserId implements IntegerIdentifier
{
    use IntegerIdentifierTrait;

    public const string PREFIX = 'usr_';
}

$id = new UserId(42);
$id->value;  // 42
$id->string; // "usr_42"

UserId::fromString('usr_42');     // UserId(42)
UserId::tryFromString('usr_abc'); // null
```

**UUID v7 / Base58 identifier** (time-sortable, URL-safe):

```
use Etel\Identifier\UuidIdentifier;
use Etel\Identifier\Implementation\Uuid\Uuid7Base58IdentifierTrait;
use Symfony\Component\Uid\Uuid;

final class OrderId implements UuidIdentifier
{
    use Uuid7Base58IdentifierTrait;

    public const string PREFIX = 'order_';
}

$id = new OrderId(Uuid::v7());
$id->value;  // UuidV7 instance
$id->string; // "order_1BvBMSEYstWetqTFn5Au4m"

OrderId::fromString('order_1BvBMSEYstWetqTFn5Au4m'); // OrderId instance
```

**String identifier**:

```
use Etel\Identifier\StringIdentifier;
use Etel\Identifier\Implementation\String\StringIdentifierTrait;

final class CountryCode implements StringIdentifier
{
    use StringIdentifierTrait;

    public const string PREFIX = 'country.';
}

$id = new CountryCode('UA');
$id->value;  // "UA"
$id->string; // "country.UA"
```

Available traits
----------------

[](#available-traits)

### Integer

[](#integer)

TraitDescription`IntegerIdentifierTrait`Positive integer (`>= 1`)### String

[](#string)

TraitDescription`StringIdentifierTrait`Non-empty string### UUID

[](#uuid)

TraitUUID versionString format`Uuid4Rfc4122IdentifierTrait`v4`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``Uuid4Base32IdentifierTrait`v426-char Crockford Base32`Uuid4Base58IdentifierTrait`v422-char Base58`Uuid7Rfc4122IdentifierTrait`v7`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``Uuid7Base32IdentifierTrait`v726-char Crockford Base32`Uuid7Base58IdentifierTrait`v722-char Base58If the built-in traits don't fit, you can implement the appropriate interface directly.

Identifiable
------------

[](#identifiable)

Mark domain objects that own an identifier with the `Identifiable` interface:

```
use Etel\Identifier\Identifiable;

final class User implements Identifiable
{
    public function __construct(public readonly UserId $id, ... ) {}
}
```

Resolving identifiers by string
-------------------------------

[](#resolving-identifiers-by-string)

`IdentifierResolver` allows resolving an identifier from its string representation without knowing the concrete type in advance. Implementations decide how identifier types are registered:

```
use Etel\Identifier\IdentifierResolver;

$resolver->fromString('usr_42');             // UserId(42)
$resolver->fromString('order_1BvBMSEY...'); // OrderId instance
$resolver->tryFromString('unknown_x');       // null
```

Todo list
---------

[](#todo-list)

- more types
- resolver implementations

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance90

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

49d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/409683?v=4)[etel](/maintainers/etel)[@etel](https://github.com/etel)

---

Top Contributors

[![relo-san](https://avatars.githubusercontent.com/u/322613?v=4)](https://github.com/relo-san "relo-san (3 commits)")

---

Tags

uuididentifierguididentifiable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/etel-identifier/health.svg)

```
[![Health](https://phpackages.com/badges/etel-identifier/health.svg)](https://phpackages.com/packages/etel-identifier)
```

###  Alternatives

[ramsey/uuid

A PHP library for generating and working with universally unique identifiers (UUIDs).

12.6k745.0M4.1k](/packages/ramsey-uuid)[pascaldevink/shortuuid

PHP 7.4+ library that generates concise, unambiguous, URL-safe UUIDs

5941.9M16](/packages/pascaldevink-shortuuid)[keiko/uuid-shortener

A simple shortener library for RFC 4122 compatible UUIDs. Change your 36 chars long UUID into it's shorter equivalent.

150227.4k3](/packages/keiko-uuid-shortener)[oittaa/uuid

A small PHP class for generating RFC 9562 universally unique identifiers (UUID) from version 3 to version 8.

54324.8k6](/packages/oittaa-uuid)[ekreative/uuid-extra-bundle

Paramconverter, Normalizer and Form Type for Ramsey Uuid

18170.8k](/packages/ekreative-uuid-extra-bundle)[identifier/identifier

Common Interfaces and Factories for Identifiers

3233.4k1](/packages/identifier-identifier)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
