Skip to content

Commit 503b240

Browse files
committed
Improve class discriminator
1 parent ddd8a24 commit 503b240

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Type/ClassType/ClassTypeDenormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
protected readonly PropertyAccessorInterface $accessor,
3434
protected readonly ClassInstantiatorInterface $instantiator,
3535
) {
36-
$this->discriminator = new DiscriminatorTypeSelector();
36+
$this->discriminator = new DiscriminatorTypeSelector($metadata);
3737
}
3838

3939
public function match(mixed $value, Context $context): bool
@@ -110,7 +110,7 @@ public function cast(mixed $value, Context $context): mixed
110110
);
111111
}
112112

113-
$discriminator = $this->discriminator->select($this->metadata, $value, $context);
113+
$discriminator = $this->discriminator->select($value, $context);
114114

115115
if ($discriminator !== null) {
116116
return $discriminator->cast($value, $context);

src/Type/ClassType/DiscriminatorTypeSelector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
final class DiscriminatorTypeSelector
1515
{
16+
public function __construct(
17+
private readonly ClassMetadata $meta,
18+
) {}
19+
1620
/**
1721
* @param array<array-key, mixed> $value
1822
*
@@ -21,9 +25,9 @@ final class DiscriminatorTypeSelector
2125
* @throws RuntimeException in case of mapped type casting error occurs
2226
* @throws \Throwable in case of internal error occurs
2327
*/
24-
public function select(ClassMetadata $meta, mixed $value, Context $context): ?TypeInterface
28+
public function select(mixed $value, Context $context): ?TypeInterface
2529
{
26-
$map = $meta->discriminator;
30+
$map = $this->meta->discriminator;
2731

2832
if ($map === null) {
2933
return null;

0 commit comments

Comments
 (0)