jeckel-lab / identity-contract
用于在域中管理身份的合约和抽象类
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-09-04 08:09:07 UTC
README
Identity-contract
本包提出用于在DDD项目中管理身份的抽象类。
特性
内置类型化身份
- 基于整数的身份
- 基于字符串的身份
- 基于UUID的身份
此外
- 实例为只读
- 等式测试
- 请求相同的身份两次返回相同的对象
用法
整数身份
final readonly class CarId extends AbstractIntIdentity {} $id = CarId::from(25);
UUID身份
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