Skip to content

Commit 8b73304

Browse files
authored
Merge pull request #77 from patchlevel/event-dispatcher-legacy
event dispatcher
2 parents b9306c3 + 2898641 commit 8b73304

File tree

11 files changed

+510
-99
lines changed

11 files changed

+510
-99
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,40 @@ readonly class Dto
406406
}
407407
```
408408

409+
### Events
410+
411+
Another way to intervene in the extract and hydrate process is through events.
412+
There are two events: `PostExtract` and `PreHydrate`.
413+
For this functionality we use the [symfony/event-dispatcher](https://symfony.com/doc/current/components/event_dispatcher.html).
414+
415+
```php
416+
use Patchlevel\Hydrator\Cryptography\PersonalDataPayloadCryptographer;
417+
use Patchlevel\Hydrator\Cryptography\Store\CipherKeyStore;
418+
use Patchlevel\Hydrator\Metadata\Event\EventMetadataFactory;
419+
use Patchlevel\Hydrator\MetadataHydrator;
420+
use Symfony\Component\EventDispatcher\EventDispatcher;
421+
use Patchlevel\Hydrator\Event\PostExtract;
422+
use Patchlevel\Hydrator\Event\PreHydrate;
423+
424+
$eventDispatcher = new EventDispatcher();
425+
426+
$eventDispatcher->addListener(
427+
PostExtract::class,
428+
static function (PostExtract $event): void {
429+
// do something
430+
}
431+
);
432+
433+
$eventDispatcher->addListener(
434+
PreHydrate::class,
435+
static function (PreHydrate $event): void {
436+
// do something
437+
}
438+
);
439+
440+
$hydrator = new MetadataHydrator(eventDispatcher: $eventDispatcher);
441+
```
442+
409443
### Cryptography
410444

411445
The library also offers the possibility to encrypt and decrypt personal data.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"require": {
2222
"php": "~8.2.0 || ~8.3.0 || ~8.4.0",
2323
"ext-openssl": "*",
24+
"symfony/event-dispatcher": "^5.4.29|^6.4.0|^7.0.0",
2425
"symfony/type-info": "^7.2.4"
2526
},
2627
"require-dev": {

0 commit comments

Comments
 (0)