Tiny is a small reversible ID obfuscator for PHP. It encodes integers into a custom alphabet and decodes them back again.
- PHP 8.1+ baseline
- PSR-4 autoloading
- PHPUnit 10/11 test suite
- GitHub Actions CI
- Safer alphabet validation and decoding errors
composer require zackkitzmiller/tiny<?php
use ZackKitzmiller\Tiny;
$tiny = new Tiny('5SX0TEjkR1mLOw8Gvq2VyJxIFhgCAYidrclDWaM3so9bfzZpuUenKtP74QNH6B');
echo $tiny->to(5);
// E
echo $tiny->from('E');
// 5
echo $tiny->to(126);
// XX
echo $tiny->from('XX');
// 126Your alphabet must:
- contain at least 2 characters
- only contain unique characters
- stay fixed forever once you start issuing encoded IDs
Tiny throws an exception when the alphabet is invalid or when you try to decode characters that are not in the configured alphabet.
After installing dependencies, generate a fresh 62-character alphabet with:
./bin/gensetYou can also generate one in code:
$set = \ZackKitzmiller\Tiny::generateSet();The legacy Tiny::generate_set() helper is still available for backwards compatibility.
This release does introduce a package-level modernization break: Composer autoloading now uses PSR-4 for ZackKitzmiller\\ classes, so consumers relying on older PSR-0-era assumptions should verify their integration when upgrading.
The Laravel integration classes continue to autoload from the ZackKitzmiller\\Laravel5\\ namespace under src/ZackKitzmiller/Laravel5/.
composer install
composer test
composer checkThe repository still includes the original Laravel integration classes for older applications, but the package is now centered on the framework-agnostic core library.
For Laravel integration:
- Laravel 5+:
- register
ZackKitzmiller\Laravel5\TinyServiceProvider - optionally register the
ZackKitzmiller\Facades\Tinyfacade alias - publish the config with
php artisan vendor:publish --tag=tiny-config - set
TINY_KEYin your environment or runphp artisan tiny:generate
- register
- older Laravel integrations:
- register
ZackKitzmiller\TinyServiceProvider - optionally register the
ZackKitzmiller\Facades\Tinyfacade alias - publish the package configuration with the framework command your app version expects
- run
php artisan tiny:generateto persist the generated key
- register