Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Feb 26, 2024
1 parent db0bd3b commit 80b2b8c
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions docs/pages/normalizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ For example DateTime, enums or value objects. You can do that too.
However, you must define a normalizer for this so that the library knows
how to write this data to the database and load it again.

!!! note

The underlying system called hydrator exists as a library.
You can find out more details [here](https://github.com/patchlevel/hydrator).

## Usage

You have to set the normalizer to the properties using the specific normalizer class.
Expand All @@ -19,7 +24,7 @@ final class DTO
}
```

The whole thing also works with property promotion.
The whole thing also works with property promotion and readonly properties.

```php
use Patchlevel\Hydrator\Normalizer\DateTimeImmutableNormalizer;
Expand Down Expand Up @@ -180,7 +185,8 @@ To normalize a `DateTimeZone` one can use the `DateTimeZoneNormalizer`.
```php
use Patchlevel\Hydrator\Normalizer\DateTimeZoneNormalizer;

final class DTO {
final class DTO
{
#[DateTimeZoneNormalizer]
public DateTimeZone $timeZone;
}
Expand All @@ -193,7 +199,8 @@ Backed enums can also be normalized.
```php
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;

final class DTO {
final class DTO
{
#[EnumNormalizer]
public Status $status;
}
Expand All @@ -204,7 +211,8 @@ You can also specify the enum class.
```php
use Patchlevel\Hydrator\Normalizer\EnumNormalizer;

final class DTO {
final class DTO
{
#[EnumNormalizer(Status::class)]
public Status $status;
}
Expand All @@ -218,7 +226,8 @@ If you have your own AggregateRootId, you can use the `IdNormalizer`.
use Patchlevel\EventSourcing\Aggregate\Uuid;
use Patchlevel\Hydrator\Normalizer\IdNormalizer;

final class DTO {
final class DTO
{
#[IdNormalizer]
public Uuid $id;
}
Expand All @@ -230,7 +239,8 @@ Optional you can also define the type of the id.
use Patchlevel\EventSourcing\Aggregate\Uuid;
use Patchlevel\Hydrator\Normalizer\IdNormalizer;

final class DTO {
final class DTO
{
#[IdNormalizer(Uuid::class)]
public Uuid $id;
}
Expand All @@ -244,7 +254,8 @@ Internally, it uses the `Hydrator` to normalize and denormalize the object.
```php
use Patchlevel\Hydrator\Normalizer\ObjectNormalizer;

final class DTO {
final class DTO
{
#[ObjectNormalizer]
public ComplexObject $object;
}
Expand All @@ -255,7 +266,8 @@ Optional you can also define the type of the object.
```php
use Patchlevel\Hydrator\Normalizer\ObjectNormalizer;

final class DTO {
final class DTO
{
#[ObjectNormalizer(ComplexObject::class)]
public object $object;
}
Expand Down Expand Up @@ -375,3 +387,25 @@ The whole thing looks like this
NormalizedName also works for snapshots.
But since a snapshot is just a cache, you can also just invalidate it,
if you have backwards compatibility break in the property name

## Ignore

You can also ignore properties with the `Ignore` attribute.

```php
use Patchlevel\Hydrator\Attribute\Ignore;

final class DTO
{
#[Ignore]
public string $name
}
```

## Learn more

* [How to use the Hydrator](https://github.com/patchlevel/hydrator)
* [How to define aggregates](aggregate.md)
* [How to snapshot aggregates](snapshots.md)
* [How to create own aggregate id](aggregate_id.md)
* [How to define events](events.md)

0 comments on commit 80b2b8c

Please sign in to comment.