Skip to content

Commit 9416083

Browse files
authored
fix(state): object mapper aware interface (#7486)
1 parent 1698120 commit 9416083

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/State/ObjectMapper/ObjectMapper.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
namespace ApiPlatform\State\ObjectMapper;
1515

16+
use ApiPlatform\Metadata\Exception\RuntimeException;
1617
use Symfony\Component\ObjectMapper\ObjectMapperAwareInterface;
1718
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
1819

19-
final class ObjectMapper implements ObjectMapperInterface, ClearObjectMapInterface
20+
final class ObjectMapper implements ObjectMapperInterface, ClearObjectMapInterface, ObjectMapperAwareInterface
2021
{
2122
private ?\SplObjectStorage $objectMap = null;
2223

@@ -48,4 +49,15 @@ public function clearObjectMap(): void
4849
$this->objectMap->detach($k);
4950
}
5051
}
52+
53+
public function withObjectMapper(ObjectMapperInterface $objectMapper): static
54+
{
55+
if (!$this->decorated instanceof ObjectMapperAwareInterface) {
56+
throw new RuntimeException(\sprintf('Given object mapper "%s" does not implements %s.', get_debug_type($this->decorated), ObjectMapperAwareInterface::class));
57+
}
58+
59+
$this->decorated->withObjectMapper($objectMapper);
60+
61+
return $this;
62+
}
5163
}

0 commit comments

Comments
 (0)