Skip to content

Commit 2b345c4

Browse files
committed
update
1 parent f9137a9 commit 2b345c4

22 files changed

Lines changed: 313 additions & 274 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": "~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0",
2323
"doctrine/dbal": "^4.0.0",
2424
"doctrine/migrations": "^3.3.2",
25-
"patchlevel/hydrator": "^1.8.0",
25+
"patchlevel/hydrator": "^2.0.x-dev",
2626
"patchlevel/worker": "^1.4.0",
2727
"psr/cache": "^2.0.0 || ^3.0.0",
2828
"psr/clock": "^1.0",

composer.lock

Lines changed: 218 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ powered by the reliable Doctrine ecosystem and focused on developer experience.
1111
* Automatic [snapshot](snapshots.md)-system to boost your performance
1212
* [Split](split-stream.md) big aggregates into multiple streams
1313
* Versioned and managed lifecycle of [subscriptions](subscription.md) like projections and processors
14-
* Safe usage of [Personal Data](personal-data.md) with crypto-shredding
14+
* Safe usage of [Personal Data](sensitive-data.md) with crypto-shredding
1515
* Smooth [upcasting](upcasting.md) of old events
1616
* Simple setup with [scheme management](store.md) and [doctrine migration](store.md)
1717
* Built in [cli commands](cli.md) with [symfony](https://symfony.com/)

docs/normalizer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ final class CreateHotel
101101
```
102102

103103
:::note
104-
If you have personal data, you can use [crypto-shredding](personal-data.md).
104+
If you have personal data, you can use [crypto-shredding](sensitive_data.md).
105105
:::
106106

107107
### Aggregate
@@ -472,4 +472,4 @@ final class DTO
472472
* [How to define aggregates](aggregate.md)
473473
* [How to define events](events.md)
474474
* [How to snapshot aggregates](snapshots.md)
475-
* [How to work with personal data](personal-data.md)
475+
* [How to work with personal data](sensitive-data.md)
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Personal Data (GDPR)
1+
# Sensitive Data
22

33
According to GDPR, personal data must be able to be deleted upon request.
44
But here we have the problem that our events are immutable and we cannot easily manipulate the event store.
@@ -42,48 +42,47 @@ final class EmailChanged
4242

4343
:::tip
4444
You can use the `DataSubjectId` in aggregates for snapshots too.
45-
:::
46-
47-
### PersonalData
45+
:::
46+
### SensitiveData
4847

49-
Next, you have to mark the properties that should be encrypted with the `#[PersonalData]` attribute.
48+
Next, you have to mark the properties that should be encrypted with the `#[SensitiveData]` attribute.
5049

5150
```php
5251
use Patchlevel\EventSourcing\Identifier\Uuid;
5352
use Patchlevel\Hydrator\Attribute\DataSubjectId;
54-
use Patchlevel\Hydrator\Attribute\PersonalData;
53+
use Patchlevel\Hydrator\Attribute\SensitiveData;
5554

5655
final class EmailChanged
5756
{
5857
public function __construct(
5958
#[DataSubjectId]
6059
public readonly Uuid $profileId,
61-
#[PersonalData]
60+
#[SensitiveData]
6261
public readonly string|null $email,
6362
) {
6463
}
6564
}
6665
```
6766

6867
:::tip
69-
You can use the `PersonalData` in aggregates for snapshots too.
68+
You can use the `SensitiveData` in aggregates for snapshots too.
7069
:::
7170

7271
If the information could not be decrypted, then a fallback value will be used.
7372
The default fallback value is `null`.
7473
You can change this by setting the `fallback` parameter or using the `fallbackCallable` parameter.
7574

7675
```php
77-
use Patchlevel\Hydrator\Attribute\PersonalData;
76+
use Patchlevel\Hydrator\Attribute\SensitiveData;
7877

7978
final class ProfileChanged
8079
{
8180
public function __construct(
8281
#[DataSubjectId]
8382
public readonly Uuid $profileId,
84-
#[PersonalData(fallback: 'unknown')]
83+
#[SensitiveData(fallback: 'unknown')]
8584
public readonly string $name,
86-
#[PersonalData(fallbackCallable: [self::class, 'createAnonymousEmail'])]
85+
#[SensitiveData(fallbackCallable: [self::class, 'createAnonymousEmail'])]
8786
public readonly string $email,
8887
) {
8988
}
@@ -147,10 +146,10 @@ Now we have to put the whole thing together in a Personal Data Payload Cryptogra
147146

148147
```php
149148
use Patchlevel\EventSourcing\Cryptography\Store\CipherKeyStore;
150-
use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer;
149+
use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer;
151150

152151
/** @var CipherKeyStore $cipherKeyStore */
153-
$cryptographer = PersonalDataPayloadCryptographer::createWithDefaultSettings($cipherKeyStore);
152+
$cryptographer = SensitiveDataPayloadCryptographer::createWithDefaultSettings($cipherKeyStore);
154153
```
155154

156155
:::tip
@@ -163,9 +162,9 @@ The last step is to integrate the cryptographer into the event store.
163162

164163
```php
165164
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
166-
use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer;
165+
use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer;
167166

168-
/** @var PersonalDataPayloadCryptographer $cryptographer */
167+
/** @var SensitiveDataPayloadCryptographer $cryptographer */
169168
DefaultEventSerializer::createFromPaths(
170169
[__DIR__ . '/Events'],
171170
cryptographer: $cryptographer,
@@ -182,9 +181,9 @@ And for the snapshot store.
182181

183182
```php
184183
use Patchlevel\EventSourcing\Snapshot\DefaultSnapshotStore;
185-
use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer;
184+
use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer;
186185

187-
/** @var PersonalDataPayloadCryptographer $cryptographer */
186+
/** @var SensitiveDataPayloadCryptographer $cryptographer */
188187
$snapshotStore = DefaultSnapshotStore::createDefault(
189188
[
190189
/* adapters... */
@@ -212,7 +211,7 @@ use Patchlevel\EventSourcing\Message\Message;
212211
use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
213212

214213
#[Processor('delete_personal_data')]
215-
final class DeletePersonalDataProcessor
214+
final class DeleteSensitiveDataProcessor
216215
{
217216
public function __construct(
218217
private readonly CipherKeyStore $cipherKeyStore,

docs/snapshots.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,4 @@ You still have to bring the aggregate up to date by loading the missing events f
265265
* [How to define aggregates](aggregate.md)
266266
* [How to store and load aggregates](repository.md)
267267
* [How to split streams](split-stream.md)
268-
* [How to work with personal data](personal-data.md)
268+
* [How to work with personal data](sensitive-data.md)

src/Message/Serializer/DefaultHeadersSerializer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Patchlevel\EventSourcing\Metadata\Message\MessageHeaderRegistry;
99
use Patchlevel\EventSourcing\Serializer\Encoder\Encoder;
1010
use Patchlevel\EventSourcing\Serializer\Encoder\JsonEncoder;
11+
use Patchlevel\Hydrator\CoreExtension;
1112
use Patchlevel\Hydrator\Hydrator;
13+
use Patchlevel\Hydrator\HydratorBuilder;
1214
use Patchlevel\Hydrator\MetadataHydrator;
1315

1416
use function is_array;
@@ -65,7 +67,7 @@ public static function createFromPaths(array $paths): static
6567
{
6668
return new self(
6769
(new AttributeMessageHeaderRegistryFactory())->create($paths),
68-
new MetadataHydrator(),
70+
(new HydratorBuilder())->useExtension(new CoreExtension())->build(),
6971
new JsonEncoder(),
7072
);
7173
}
@@ -74,7 +76,7 @@ public static function createDefault(): static
7476
{
7577
return new self(
7678
MessageHeaderRegistry::createWithInternalHeaders(),
77-
new MetadataHydrator(),
79+
(new HydratorBuilder())->useExtension(new CoreExtension())->build(),
7880
new JsonEncoder(),
7981
);
8082
}

src/Serializer/DefaultEventSerializer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
use Patchlevel\EventSourcing\Serializer\Encoder\JsonEncoder;
1111
use Patchlevel\EventSourcing\Serializer\Upcast\Upcast;
1212
use Patchlevel\EventSourcing\Serializer\Upcast\Upcaster;
13+
use Patchlevel\Hydrator\CoreExtension;
14+
use Patchlevel\Hydrator\Cryptography\CryptographyExtension;
1315
use Patchlevel\Hydrator\Cryptography\PayloadCryptographer;
1416
use Patchlevel\Hydrator\Hydrator;
15-
use Patchlevel\Hydrator\MetadataHydrator;
17+
use Patchlevel\Hydrator\HydratorBuilder;
1618

1719
final class DefaultEventSerializer implements EventSerializer
1820
{
1921
public function __construct(
2022
private EventRegistry $eventRegistry,
21-
private Hydrator $hydrator = new MetadataHydrator(),
23+
private Hydrator $hydrator,
2224
private Encoder $encoder = new JsonEncoder(),
2325
private Upcaster|null $upcaster = null,
2426
) {
@@ -59,9 +61,16 @@ public static function createFromPaths(
5961
Upcaster|null $upcaster = null,
6062
PayloadCryptographer|null $cryptographer = null,
6163
): static {
64+
$builder = (new HydratorBuilder())
65+
->useExtension(new CoreExtension());
66+
67+
if ($cryptographer) {
68+
$builder->useExtension(new CryptographyExtension($cryptographer));
69+
}
70+
6271
return new self(
6372
(new AttributeEventRegistryFactory())->create($paths),
64-
new MetadataHydrator(cryptographer: $cryptographer),
73+
$builder->build(),
6574
new JsonEncoder(),
6675
$upcaster,
6776
);

src/Serializer/Normalizer/IdNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
) {
2626
}
2727

28-
public function normalize(mixed $value): string|null
28+
public function normalize(mixed $value, array $context): string|null
2929
{
3030
if ($value === null) {
3131
return null;
@@ -40,7 +40,7 @@ public function normalize(mixed $value): string|null
4040
return $value->toString();
4141
}
4242

43-
public function denormalize(mixed $value): Identifier|null
43+
public function denormalize(mixed $value, array $context): Identifier|null
4444
{
4545
if ($value === null) {
4646
return null;

src/Snapshot/DefaultSnapshotStore.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootMetadataAwareMetadataFactory;
1010
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootMetadataFactory;
1111
use Patchlevel\EventSourcing\Snapshot\Adapter\SnapshotAdapter;
12+
use Patchlevel\Hydrator\CoreExtension;
13+
use Patchlevel\Hydrator\Cryptography\CryptographyExtension;
1214
use Patchlevel\Hydrator\Cryptography\PayloadCryptographer;
1315
use Patchlevel\Hydrator\Hydrator;
14-
use Patchlevel\Hydrator\MetadataHydrator;
16+
use Patchlevel\Hydrator\HydratorBuilder;
1517
use Throwable;
16-
1718
use function array_key_exists;
1819
use function is_array;
1920
use function sprintf;
@@ -38,7 +39,7 @@ public function __construct(
3839
$this->adapterRepository = $adapterRepository;
3940
}
4041

41-
$this->hydrator = $hydrator ?? new MetadataHydrator();
42+
$this->hydrator = $hydrator ?? (new HydratorBuilder())->useExtension(new CoreExtension())->build();;
4243
$this->metadataFactory = $metadataFactory ?? new AggregateRootMetadataAwareMetadataFactory();
4344
}
4445

@@ -120,9 +121,16 @@ private function version(string $aggregateClass): string|null
120121
/** @param array<string, SnapshotAdapter> $snapshotAdapters */
121122
public static function createDefault(array $snapshotAdapters, PayloadCryptographer|null $cryptographer = null): self
122123
{
124+
$builder = new HydratorBuilder();
125+
$builder->useExtension(new CoreExtension());
126+
127+
if ($cryptographer) {
128+
$builder->useExtension(new CryptographyExtension($cryptographer));
129+
}
130+
123131
return new self(
124132
new ArrayAdapterRepository($snapshotAdapters),
125-
new MetadataHydrator(cryptographer: $cryptographer),
133+
$builder->build(),
126134
);
127135
}
128136
}

0 commit comments

Comments
 (0)