Skip to content

Commit db27fe6

Browse files
authored
Merge branch '2.0.x' into 1.23.x-merge-up-into-2.0.x_1WFnzs6Q
2 parents 7c15b9b + dd19036 commit db27fe6

156 files changed

Lines changed: 753 additions & 5011 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ phpunit: vendor
2727

2828
.PHONY: infection
2929
infection: vendor ## run infection
30-
XDEBUG_MODE=coverage vendor/bin/infection --threads=3
30+
XDEBUG_MODE=coverage php -d memory_limit=312M vendor/bin/infection --threads=3
3131

3232
.PHONY: static
3333
static: phpstan cs ## run static analysers

README.md

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
2727
To 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

3535
After that you can hydrate any classes or objects. Also `final`, `readonly` classes with `property promotion`.
@@ -501,9 +501,9 @@ class NameGuesser implements Guesser
501501
To 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`.
610610
For 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;
614614
use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
615615
use Patchlevel\Hydrator\Metadata\Event\EventMetadataFactory;
616-
use Patchlevel\Hydrator\MetadataHydrator;
616+
use Patchlevel\Hydrator\StackHydrator;
617617
use Symfony\Component\EventDispatcher\EventDispatcher;
618618
use Patchlevel\Hydrator\Event\PostExtract;
619619
use 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
671684
use Patchlevel\Hydrator\Attribute\DataSubjectId;
672-
use Patchlevel\Hydrator\Attribute\PersonalData;
685+
use Patchlevel\Hydrator\Attribute\SensitiveData;
673686

674687
final 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+
686706
If the information could not be decrypted, then a fallback value is inserted.
687707
The default fallback value is `null`.
688708
You can change this by setting the `fallback` parameter.
689709
In this case `unknown` is added:
690710

691711
```php
692-
use Patchlevel\Hydrator\Attribute\PersonalData;
712+
use Patchlevel\Hydrator\Attribute\SensitiveData;
693713

694714
final 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
709729
use Patchlevel\Hydrator\Attribute\DataSubjectId;
710-
use Patchlevel\Hydrator\Attribute\PersonalData;
730+
use Patchlevel\Hydrator\Attribute\SensitiveData;
711731

712732
final 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
737757
Here we show you how to configure the cryptography.
738758

739759
```php
740-
use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer;
760+
use Patchlevel\Hydrator\Cryptography\SensitiveDataPayloadCryptographer;
741761
use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
742762
use 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]

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"ext-openssl": "*",
2424
"psr/cache": "^2.0.0 || ^3.0.0",
2525
"psr/simple-cache": "^2.0.0 || ^3.0.0",
26-
"symfony/event-dispatcher": "^5.4.29 || ^6.4.0 || ^7.0.0 || ^8.0.0",
2726
"symfony/type-info": "^7.3.0 || ^8.0.0"
2827
},
2928
"require-dev": {

0 commit comments

Comments
 (0)