bitnix / identity
0.1.0
2025-09-01 11:27 UTC
Requires
- php: ^8.4
- ramsey/uuid: ^4.9
Requires (Dev)
- phpunit/phpunit: ^11.4
README
Small, lightweight PHP library for working with identity value objects like UUIDs. Currently only UUIDv4 and UUIDv7 are supported.
Features
- Small and easy to use
- Creates domain-specific UUID types by composing the abstract UUID class with specific traits
Installation
Install via Composer:
composer require bitnix/identity
Usage
Example: UUIDv4
namespace App\Engine;
use Bitnix\Identity\Uuid;
use Bitnix\Identity\Uuid4;
final class AppSecret extends Uuid {
use Uuid4;
}
$uuid = new AppSecret();
// or...
$value = '23a84767-8e2c-41c4-8a8d-0a64bfc1344d'; // user input, db, ...
$uuid = new AppSecret($value);
// readonly string
echo $uuid->value;
// readonly int
echo $uuid->version;
Example: UUIDv7
namespace App\Documents;
use Bitnix\Identity\Uuid;
use Bitnix\Identity\Uuid7;
final class DocumentId extends Uuid {
use Uuid7;
}
Example: UUID comparison
$uuid1 = new DocumentId();
$uuid2 = new DocumentId($uuid1->value);
if ($uuid1->equals($uuid2)) {
// same uuid value, version and type
}
Tests
Run tests with PHPUnit:
composer test
or, to get a coverage report at test/.phpunit/coverage:
composer testc
Contributing
- Fork the repo, create a feature branch, open a pull request.
- Keep changes small and documented.
- Add tests for new functionality.
License
Released under AGPL-3.0-or-later License.