Skip to content

Commit 5a640a1

Browse files
committed
middleware based hydrator
1 parent 1066e35 commit 5a640a1

27 files changed

Lines changed: 447 additions & 974 deletions

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": {

composer.lock

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

src/Attribute/PostHydrate.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Attribute/PreExtract.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Cryptography/CryptographyMetadataFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function metadata(string $class): ClassMetadata
3434

3535
if (array_key_exists($subjectIdIdentifier, $subjectIdMapping)) {
3636
throw new DuplicateSubjectIdIdentifier(
37-
$metadata->className(),
38-
$metadata->propertyForField($subjectIdMapping[$subjectIdIdentifier])->propertyName(),
39-
$property->propertyName(),
37+
$metadata->className,
38+
$metadata->propertyForField($subjectIdMapping[$subjectIdIdentifier])->propertyName,
39+
$property->propertyName,
4040
$subjectIdIdentifier,
4141
);
4242
}
@@ -53,7 +53,7 @@ public function metadata(string $class): ClassMetadata
5353
}
5454

5555
if ($isSubjectId) {
56-
throw new SubjectIdAndSensitiveDataConflict($metadata->className(), $property->propertyName());
56+
throw new SubjectIdAndSensitiveDataConflict($metadata->className, $property->propertyName);
5757
}
5858

5959
$property->extras[SensitiveDataInfo::class] = $sensitiveDataInfo;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\Hydrator\Cryptography;
6+
7+
use Patchlevel\Hydrator\Metadata\ClassMetadata;
8+
use Patchlevel\Hydrator\Middleware\Middleware;
9+
use Patchlevel\Hydrator\Middleware\Stack;
10+
11+
final class CryptographyMiddleware implements Middleware
12+
{
13+
public function __construct(
14+
private readonly PayloadCryptographer $cryptography,
15+
) {
16+
}
17+
18+
/**
19+
* @param ClassMetadata<T> $metadata
20+
* @param array<string, mixed> $data
21+
*
22+
* @return T
23+
*
24+
* @template T of object
25+
*/
26+
public function hydrate(ClassMetadata $metadata, array $data, Stack $stack): object
27+
{
28+
return $stack->next()->hydrate(
29+
$metadata,
30+
$this->cryptography->decrypt($metadata, $data),
31+
$stack,
32+
);
33+
}
34+
35+
/**
36+
* @param ClassMetadata<T> $metadata
37+
* @param T $object
38+
*
39+
* @return array<string, mixed>
40+
*
41+
* @template T of object
42+
*/
43+
public function extract(ClassMetadata $metadata, object $object, Stack $stack): array
44+
{
45+
return $this->cryptography->encrypt(
46+
$metadata,
47+
$stack->next()->extract($metadata, $object, $stack),
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)