PHPackages                             ap-lib/public-id - 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. ap-lib/public-id

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

ap-lib/public-id
================

A small PHP library for generating short, public-friendly integer IDs from internal numeric IDs. Designed to hide system scale and client-specific patterns while keeping IDs compact and reversible.

014PHP

Since Mar 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ap-lib/public-id)[ Packagist](https://packagist.org/packages/ap-lib/public-id)[ RSS](/packages/ap-lib-public-id/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AP\\PublicID
============

[](#appublicid)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

A small PHP library for generating short, public-friendly integer IDs from internal numeric IDs.

Designed to hide system scale and client-specific patterns while keeping IDs compact and reversible.

> ❗️Not for security purposes.
>
> If clients know you're using `UnsafePublicID`, they might infer ID ranges or volumes. Use `SafePublicID` for stronger obfuscation with a mask.
>
> It's still reversible and not secure, but the effort required to reverse-engineer it is significantly greater.

---

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

[](#installation)

```
composer require ap-lib/public-id
```

Features
--------

[](#features)

- Encode numeric IDs into non-sequential public integers
- Keep public-facing IDs short and opaque
- Optional masking layer to prevent reverse-engineering
- Fully reversible with `decode()`

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Getting started
---------------

[](#getting-started)

### Basic usage with `UnsafePublicID`

[](#basic-usage-with-unsafepublicid)

```
use AP\PublicID\UnsafePublicID;

$digits_divider = 2;
$original_id = 1000;

$public_id = UnsafePublicID::encode(
    int: $original_id,
    digits_divider: $digits_divider
);

$decoded_original_id = UnsafePublicID::decode(
    public: $public_id,
    digits_divider: $digits_divider
);

// $decoded_original_id equal $original_id

$public_id_2 = UnsafePublicID::encode(
    int: $original_id,
    digits_divider: $digits_divider
);

// $public_id equal $public_id_2
```

---

### Safer encoding with `SafePublicID`

[](#safer-encoding-with-safepublicid)

```
use AP\PublicID\SafePublicID;

$secret_mask_from_envs = 902734092;

$safePublicId = new SafePublicID(
    mask: $secret_mask_from_envs
);

$digits_divider = 2;
$original_id = 1000;

$public_id = $safePublicId->encode(
    int: $original_id,
    digits_divider: $digits_divider
);

$decoded_original_id = $safePublicId->decode(
    int: $public_id,
    digits_divider: $digits_divider
);

// $decoded_original_id equal $original_id

$public_id_2 = $safePublicId->encode(
    int: $original_id,
    digits_divider: $digits_divider
);

// $public_id equal $public_id_2
```

---

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1215fe5ecc9ba0ab1c730d3c992125cf6ebf460562e66be71ebae127789d465a?d=identicon)[AntonPanfilov](/maintainers/AntonPanfilov)

---

Top Contributors

[![anton-panfilov](https://avatars.githubusercontent.com/u/1083546?v=4)](https://github.com/anton-panfilov "anton-panfilov (4 commits)")

### Embed Badge

![Health badge](/badges/ap-lib-public-id/health.svg)

```
[![Health](https://phpackages.com/badges/ap-lib-public-id/health.svg)](https://phpackages.com/packages/ap-lib-public-id)
```

PHPackages © 2026

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