https://github.com/jeckel-lab/identity-contract
Propose basic abstract classes to manage Identities in Domain project
https://github.com/jeckel-lab/identity-contract
contract contracts ddd identity php php-library
Last synced: about 1 year ago
JSON representation
Propose basic abstract classes to manage Identities in Domain project
- Host: GitHub
- URL: https://github.com/jeckel-lab/identity-contract
- Owner: Jeckel-Lab
- Created: 2021-03-09T14:53:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T07:04:52.000Z (over 2 years ago)
- Last Synced: 2025-05-15T19:09:18.234Z (about 1 year ago)
- Topics: contract, contracts, ddd, identity, php, php-library
- Language: PHP
- Homepage: https://jeckel-lab.fr
- Size: 72.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://packagist.org/packages/jeckel-lab/identity-contract)
[](https://packagist.org/packages/jeckel-lab/identity-contract)
[](https://github.com/Jeckel-Lab/identity-contract/actions)
[](https://codecov.io/gh/Jeckel-Lab/identity-contract)
[](https://dashboard.stryker-mutator.io/reports/github.com/Jeckel-Lab/identity-contract/main)
# Identity-contract
| PHP Version | Package version |
| ---------- | ---------------- |
| PHP >= 8.2 | v2.0 |
| PHP >= 8.0 | v1.1 |
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**
```PHP
final readonly class CarId extends AbstractIntIdentity {}
$id = CarId::from(25);
```
**UUID Identity**
```PHP
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
```