1- [ ![ Mutation testing badge] ( https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fpatchlevel%2Fhydrator%2F1.13 .x )] ( https://dashboard.stryker-mutator.io/reports/github.com/patchlevel/hydrator/1.13 .x )
1+ [ ![ Mutation testing badge] ( https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fpatchlevel%2Fhydrator%2F2.0 .x )] ( https://dashboard.stryker-mutator.io/reports/github.com/patchlevel/hydrator/2.0 .x )
22[ ![ Latest Stable Version] ( https://poser.pugx.org/patchlevel/hydrator/v )] ( //packagist.org/packages/patchlevel/hydrator )
33[ ![ License] ( https://poser.pugx.org/patchlevel/hydrator/license )] ( //packagist.org/packages/patchlevel/hydrator )
44
@@ -27,9 +27,9 @@ composer require patchlevel/hydrator
2727To use the hydrator you just have to create an instance of it.
2828
2929``` php
30- use Patchlevel\Hydrator\MetadataHydrator ;
30+ use Patchlevel\Hydrator\StackHydrator ;
3131
32- $hydrator = MetadataHydrator ::create();
32+ $hydrator = StackHydrator ::create();
3333```
3434
3535After that you can hydrate any classes or objects. Also ` final ` , ` readonly ` classes with ` property promotion ` .
@@ -501,9 +501,9 @@ class NameGuesser implements Guesser
501501To use this Guesser, you must specify it when creating the Hydrator:
502502
503503``` php
504- use Patchlevel\Hydrator\MetadataHydrator ;
504+ use Patchlevel\Hydrator\StackHydrator ;
505505
506- $hydrator = MetadataHydrator ::create([new NameGuesser()]);
506+ $hydrator = StackHydrator ::create([new NameGuesser()]);
507507```
508508
509509> [ !NOTE]
@@ -610,10 +610,10 @@ There are two events: `PostExtract` and `PreHydrate`.
610610For this functionality we use the [ symfony/event-dispatcher] ( https://symfony.com/doc/current/components/event_dispatcher.html ) .
611611
612612``` php
613- use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer ;
613+ use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer ;
614614use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
615615use Patchlevel\Hydrator\Metadata\Event\EventMetadataFactory;
616- use Patchlevel\Hydrator\MetadataHydrator ;
616+ use Patchlevel\Hydrator\StackHydrator ;
617617use Symfony\Component\EventDispatcher\EventDispatcher;
618618use Patchlevel\Hydrator\Event\PostExtract;
619619use Patchlevel\Hydrator\Event\PreHydrate;
@@ -634,13 +634,13 @@ $eventDispatcher->addListener(
634634 }
635635);
636636
637- $hydrator = new MetadataHydrator (eventDispatcher: $eventDispatcher);
637+ $hydrator = new StackHydrator (eventDispatcher: $eventDispatcher);
638638```
639639
640640### Cryptography
641641
642- The library also offers the possibility to encrypt and decrypt personal data.
643- For this purpose, a key is created for each subject ID, which is used to encrypt the personal data.
642+ The library also offers the possibility to encrypt and decrypt sensitive data, e.g. personal data of customers .
643+ For this purpose, a key is created for each subject ID, which is used to encrypt the sensitive data.
644644
645645#### DataSubjectId
646646
@@ -661,42 +661,62 @@ final class EmailChanged
661661
662662> [ !WARNING]
663663> The ` DataSubjectId ` must be a string. You can use a normalizer to convert it to a string.
664- > The Subject ID cannot be personal data.
664+ > The Subject ID cannot be sensitive data.
665665
666- #### PersonalData
666+ First we need to define what the subject id is.
667667
668- Next, we need to specify which fields we want to encrypt.
668+ ``` php
669+ use Patchlevel\Hydrator\Attribute\DataSubjectId;
670+
671+ final class EmailChanged
672+ {
673+ public function __construct(
674+ #[DataSubjectId(name: 'profile')]
675+ public readonly string $profileId,
676+ ) {
677+ }
678+ }
679+ ```
680+
681+ You can also use multiple data subject id's in one event by defining the name of the subject id's.
669682
670683``` php
671684use Patchlevel\Hydrator\Attribute\DataSubjectId;
672- use Patchlevel\Hydrator\Attribute\PersonalData ;
685+ use Patchlevel\Hydrator\Attribute\SensitiveData ;
673686
674687final class DTO
675688{
676689 public function __construct(
677- #[DataSubjectId]
678- public readonly string $profileId,
679- #[PersonalData]
680- public readonly string|null $email,
690+ #[DataSubjectId(name: 'profile1')]
691+ public readonly string $profile1Id,
692+ #[SensitiveData(subjectIdName: 'profile1')]
693+ public readonly string|null $email1,
694+ #[DataSubjectId(name: 'profile2')]
695+ public readonly string $profile2Id,
696+ #[SensitiveData(subjectIdName: 'profile2')]
697+ public readonly string|null $email2,
681698 ) {
682699 }
683700}
684701```
685702
703+ > [ !NOTE]
704+ > The default name of ` DataSubjectId ` is ` default ` .
705+
686706If the information could not be decrypted, then a fallback value is inserted.
687707The default fallback value is ` null ` .
688708You can change this by setting the ` fallback ` parameter.
689709In this case ` unknown ` is added:
690710
691711``` php
692- use Patchlevel\Hydrator\Attribute\PersonalData ;
712+ use Patchlevel\Hydrator\Attribute\SensitiveData ;
693713
694714final class DTO
695715{
696716 public function __construct(
697717 #[DataSubjectId]
698718 public readonly string $profileId,
699- #[PersonalData (fallback: 'unknown')]
719+ #[SensitiveData (fallback: 'unknown')]
700720 public readonly string $name,
701721 ) {
702722 }
@@ -707,16 +727,16 @@ You can also use a callable as a fallback.
707727
708728``` php
709729use Patchlevel\Hydrator\Attribute\DataSubjectId;
710- use Patchlevel\Hydrator\Attribute\PersonalData ;
730+ use Patchlevel\Hydrator\Attribute\SensitiveData ;
711731
712732final class ProfileCreated
713733{
714734 public function __construct(
715735 #[DataSubjectId]
716736 public readonly string $profileId,
717- #[PersonalData (fallback: 'deleted profile')]
737+ #[SensitiveData (fallback: 'deleted profile')]
718738 public readonly string $name,
719- #[PersonalData (fallbackCallable: [self::class, 'anonymizedEmail'])]
739+ #[SensitiveData (fallbackCallable: [self::class, 'anonymizedEmail'])]
720740 public readonly string $email,
721741 ) {
722742 }
@@ -737,14 +757,14 @@ final class ProfileCreated
737757Here we show you how to configure the cryptography.
738758
739759``` php
740- use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer ;
760+ use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer ;
741761use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
742762use Patchlevel\Hydrator\Metadata\Event\EventMetadataFactory;
743- use Patchlevel\Hydrator\MetadataHydrator ;
763+ use Patchlevel\Hydrator\StackHydrator ;
744764
745765$cipherKeyStore = new InMemoryCipherKeyStore();
746- $cryptographer = PersonalDataPayloadCryptographer ::createWithDefaultSettings($cipherKeyStore);
747- $hydrator = new MetadataHydrator (cryptographer: $cryptographer);
766+ $cryptographer = SensitiveDataPayloadCryptographer ::createWithDefaultSettings($cipherKeyStore);
767+ $hydrator = new StackHydrator (cryptographer: $cryptographer);
748768```
749769
750770> [ !WARNING]
0 commit comments