From 80b2b8c2ff3b967f95d2829dd618a21126555033 Mon Sep 17 00:00:00 2001 From: David Badura Date: Mon, 26 Feb 2024 10:13:54 +0100 Subject: [PATCH] update docs --- docs/pages/normalizer.md | 50 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/docs/pages/normalizer.md b/docs/pages/normalizer.md index 6c6eff3b3..5b86c5916 100644 --- a/docs/pages/normalizer.md +++ b/docs/pages/normalizer.md @@ -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. @@ -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; @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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) \ No newline at end of file