|
2 | 2 | [](LICENSE) |
3 | 3 | [](http://www.php.net) |
4 | 4 |
|
5 | | -Gember Identity generator ([gember/event-sourcing](https://github.com/GemberPHP/event-sourcing)) implementation based on [symfony/uid](https://github.com/symfony/uid). |
| 5 | +[Gember Event Sourcing](https://github.com/GemberPHP/event-sourcing) Identity Generator adapter based on [symfony/uid](https://github.com/symfony/uid). |
| 6 | + |
| 7 | +> All external dependencies in Gember Event Sourcing are organized into separate packages, |
| 8 | +> making it easy to swap out a vendor adapter for another. |
| 9 | +
|
| 10 | +## Installation |
| 11 | +Install with Composer: |
| 12 | +```bash |
| 13 | +composer require gember/identity-generator-symfony |
| 14 | +``` |
| 15 | + |
| 16 | +## Configuration |
| 17 | +Bind this adapter to the `IdentityGenerator` interface in your service definitions. |
| 18 | + |
| 19 | +### Examples |
| 20 | + |
| 21 | +#### Vanilla PHP |
| 22 | +```php |
| 23 | +use Gember\IdentityGeneratorSymfony\Ulid\SymfonyUlidIdentityGenerator; |
| 24 | +use Gember\IdentityGeneratorSymfony\Uuid\SymfonyUuidIdentityGenerator; |
| 25 | +use Symfony\Component\Uid\Factory\UlidFactory; |
| 26 | +use Symfony\Component\Uid\Factory\UuidFactory; |
| 27 | + |
| 28 | +# ULID Identity Generator |
| 29 | +$ulidIdentityGenerator = new SymfonyUlidIdentityGenerator( |
| 30 | + new UlidFactory(), |
| 31 | +); |
| 32 | + |
| 33 | +# UUID (v4) Identity Generator |
| 34 | +$uuidIdentityGenerator = new SymfonyUuidIdentityGenerator( |
| 35 | + new UuidFactory(), |
| 36 | +); |
| 37 | +``` |
| 38 | + |
| 39 | +#### Symfony |
| 40 | +It is recommended to use the [Symfony bundle](https://github.com/GemberPHP/event-sourcing-symfony-bundle) to configure Gember Event Sourcing. |
| 41 | +With this bundle, the UUID adapter is automatically set as the default for Identity Generator. |
| 42 | + |
| 43 | +If you're not using the bundle, you can bind it directly to the `IdentityGenerator` interface. |
| 44 | + |
| 45 | +```yaml |
| 46 | +# Bind ULID Identity Generator to interface |
| 47 | +Gember\EventSourcing\Util\Generator\Identity\IdentityGenerator: |
| 48 | + class: Gember\IdentityGeneratorSymfony\Ulid\SymfonyUlidIdentityGenerator |
| 49 | + arguments: |
| 50 | + - '@ Symfony\Component\Uid\Factory\UlidFactory' |
| 51 | + |
| 52 | +# OR bind UUID (v4) Identity Generator to interface |
| 53 | +Gember\EventSourcing\Util\Generator\Identity\IdentityGenerator: |
| 54 | + class: Gember\IdentityGeneratorSymfony\Uuid\SymfonyUuidIdentityGenerator |
| 55 | + arguments: |
| 56 | + - '@ Symfony\Component\Uid\Factory\UuidFactory' |
| 57 | +``` |
0 commit comments