Skip to content

Commit

Permalink
upgrade hydrator & use new auto detect feature
Browse files Browse the repository at this point in the history
DavidBadura committed Feb 26, 2024
1 parent 6dd1cab commit db0bd3b
Showing 33 changed files with 209 additions and 309 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"doctrine/dbal": "^3.8.1|^4.0.0",
"doctrine/migrations": "^3.3.2",
"patchlevel/hydrator": "^1.1.0",
"patchlevel/hydrator": "^1.2.0",
"patchlevel/worker": "^1.1.1",
"psr/cache": "^2.0.0|^3.0.0",
"psr/clock": "^1.0",
76 changes: 38 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pages/aggregate.md
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
final class ProfileRegistered
{
public function __construct(
#[IdNormalizer(Uuid::class)]
#[IdNormalizer]
public readonly Uuid $profileId,
public readonly string $name
) {}
6 changes: 3 additions & 3 deletions docs/pages/aggregate_id.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
final class Profile extends BasicAggregateRoot
{
#[Id]
#[IdNormalizer(Uuid::class)]
#[IdNormalizer]
private Uuid $id;
}
```
@@ -68,7 +68,7 @@ use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
final class Profile extends BasicAggregateRoot
{
#[Id]
#[IdNormalizer(CustomId::class)]
#[IdNormalizer]
private CustomId $id;
}
```
@@ -127,7 +127,7 @@ use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
final class Profile extends BasicAggregateRoot
{
#[Id]
#[IdNormalizer(ProfileId::class)]
#[IdNormalizer]
private ProfileId $id;
}
```
2 changes: 1 addition & 1 deletion docs/pages/events.md
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ use Patchlevel\Hydrator\Normalizer\IdNormalizer;
final class ProfileCreated
{
public function __construct(
#[IdNormalizer(Uuid::class)]
#[IdNormalizer]
public readonly Uuid $id,
#[NameNormalizer]
public readonly Name $name,
2 changes: 1 addition & 1 deletion docs/pages/getting_started.md
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
final class HotelCreated
{
public function __construct(
#[IdNormalizer(Uuid::class)]
#[IdNormalizer]
public readonly Uuid $hotelId,
public readonly string $hotelName
) {
50 changes: 48 additions & 2 deletions docs/pages/normalizer.md
Original file line number Diff line number Diff line change
@@ -189,7 +189,17 @@ final class DTO {
### Enum

Backed enums can also be normalized.
For this, the enum FQCN must also be pass so that the `EnumNormalizer` knows which enum it is.

```php
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;

final class DTO {
#[EnumNormalizer]
public Status $status;
}
```

You can also specify the enum class.

```php
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;
@@ -203,7 +213,18 @@ final class DTO {
### Id

If you have your own AggregateRootId, you can use the `IdNormalizer`.
the `IdNormalizer` needs the FQCN of the AggregateRootId as a parameter.

```php
use Patchlevel\EventSourcing\Aggregate\Uuid;
use Patchlevel\Hydrator\Normalizer\IdNormalizer;

final class DTO {
#[IdNormalizer]
public Uuid $id;
}
```

Optional you can also define the type of the id.

```php
use Patchlevel\EventSourcing\Aggregate\Uuid;
@@ -215,6 +236,31 @@ final class DTO {
}
```

### Object

If you have a complex object that you want to normalize, you can use the `ObjectNormalizer`.
Internally, it uses the `Hydrator` to normalize and denormalize the object.

```php
use Patchlevel\Hydrator\Normalizer\ObjectNormalizer;

final class DTO {
#[ObjectNormalizer]
public ComplexObject $object;
}
```

Optional you can also define the type of the object.

```php
use Patchlevel\Hydrator\Normalizer\ObjectNormalizer;

final class DTO {
#[ObjectNormalizer(ComplexObject::class)]
public object $object;
}
```

## Custom Normalizer

Since we only offer normalizers for PHP native things,
6 changes: 5 additions & 1 deletion docs/pages/split_stream.md
Original file line number Diff line number Diff line change
@@ -17,12 +17,16 @@ loaded anymore for building the aggregate. This means that all needed data has t
should trigger the event split.

```php
use Patchlevel\EventSourcing\Attribute\Event;
use Patchlevel\EventSourcing\Attribute\SplitStream;
use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;

#[Event('bank_account.month_passed')]
#[SplitStream]
final class MonthPassed
{
public function __construct(
#[Normalize(new AccountIdNormalizer())]
#[IdNormalizer]
public AccountId $accountId,
public string $name,
public int $balanceInCents,
Loading

0 comments on commit db0bd3b

Please sign in to comment.