Skip to content

Commit 7730cb1

Browse files
committed
update readme
1 parent 7e23e6b commit 7730cb1

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
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.

src/Metadata/AttributeMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private function findNormalizer(ReflectionProperty $reflectionProperty, Type $ty
423423
$normalizer = $this->findNormalizerOnClass(new ReflectionClass($valueType->getClassName()));
424424

425425
if ($normalizer === null) {
426-
return $normalizer;
426+
return null;
427427
}
428428

429429
if ($normalizer instanceof TypeAwareNormalizer) {

tests/Unit/Metadata/AttributeMetadataFactoryTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function testEmptyObject(): void
4747
self::assertCount(0, $metadata->postHydrateCallbacks());
4848
}
4949

50+
public function testSameMetadata(): void
51+
{
52+
$object = new class {
53+
};
54+
55+
$metadataFactory = new AttributeMetadataFactory();
56+
57+
self::assertSame($metadataFactory->metadata($object::class), $metadataFactory->metadata($object::class));
58+
}
59+
5060
public function testNotFoundProperty(): void
5161
{
5262
$this->expectException(PropertyMetadataNotFound::class);

0 commit comments

Comments
 (0)