freyr / identity
A PHP library for Identity concept.
Installs: 226
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/freyr/identity
Requires
- php: ^8.2 || ^8.3 || ^8.4
- ramsey/uuid: ^4.7
- symfony/polyfill-php84: ^1.31
Requires (Dev)
- ergebnis/composer-normalize: ^2.45
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.0 || ^12.0
- symplify/easy-coding-standard: ^12.5
This package is auto-updated.
Last update: 2026-02-07 21:02:14 UTC
README
UUID v7 identity objects for PHP domain models. Provides an immutable Id value object and an IdCollection for working with sets of identifiers.
Installation
composer require freyr/identity
Requires PHP 8.2+.
Usage
Id
Create, convert and compare identifiers.
use Freyr\Identity\Id; $id = Id::new(); $id = Id::fromString('01920a7c-8b00-7000-8000-000000000001'); $id = Id::fromBinary($bytes); (string) $id; // UUID string $id->toBinary(); // 16-byte binary $id->sameAs($other);
Extend for typed identifiers.
class UserId extends Id {} $userId = UserId::new();
IdCollection
Immutable collection with standard operations.
use Freyr\Identity\IdCollection; $collection = IdCollection::fromArray([$id1, $id2]); $collection = IdCollection::empty(); $collection->add($id); $collection->remove($id); $collection->contains($id); $collection->merge($other); $collection->intersect($other); $collection->filter(fn (Id $id) => /* ... */); $collection->map(fn (Id $id) => /* ... */); $collection->first(); $collection->last(); $collection->count(); $collection->isEmpty(); $collection->toArray(); $collection->toStringArray(); $collection->toBinaryArray();
All mutating methods return new instances.
Licence
MIT