jeckel-lab / identity-contract
Contract and abstract classes to manage identities in Domains
v2.0.0
2023-10-16 09:14 UTC
Requires
- php: >=8.2
- jeckel-lab/contract: ^2.3
- ramsey/uuid: ^4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.34
- infection/infection: ^0.27
- maglnet/composer-require-checker: ^3||^4
- phpmd/phpmd: ^2.11
- phpro/grumphp: ^2.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.2
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^10.4
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-11-04 08:38:44 UTC
README
Identity-contract
This package propose abstract classes to manage Identities in DDD projects.
Features
Builtin typed identities :
- integer based identities
- string based identities
- uuid based identities
Also:
- instance are readonly
- equality test
- request same identity twice return same object
Usage
Int Identity
final readonly class CarId extends AbstractIntIdentity {} $id = CarId::from(25);
UUID Identity
use JeckelLab\IdentityContract\AbstractUuidIdentity; final readonly class UserId extends AbstractUuidIdentity {} $id = UserId::from("d2fbc6c0-0497-42f1-8ece-8840641b67f0"); // or $id = UserId::new(); // Generating twice same identity return same object $id1 = UserId::from("d2fbc6c0-0497-42f1-8ece-8840641b67f0"); $id2 = UserId::from("d2fbc6c0-0497-42f1-8ece-8840641b67f0"); var_dump($id1 === $id2); // true