Skip to content

Commit 27e545b

Browse files
committed
Use context variable to detect whether transformed
When a DataTransformer returns the original resource as a fallback, a context key is set so when repeating the serialization/normalization we can populate the extended jsonld data
1 parent 4413451 commit 27e545b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function supportsNormalization($data, $format = null): bool
6565
*/
6666
public function normalize($object, $format = null, array $context = [])
6767
{
68+
6869
$objectClass = $this->getObjectClass($object);
6970
$outputClass = $this->getOutputClass($objectClass, $context);
7071
if (null !== $outputClass && !isset($context[self::IS_TRANSFORMED_TO_SAME_CLASS_CONTEXT_KEY])) {

src/Serializer/AbstractItemNormalizer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function hasCacheableSupportsMethod(): bool
114114
*/
115115
public function normalize($object, $format = null, array $context = [])
116116
{
117+
117118
if (!($isTransformed = isset($context[self::IS_TRANSFORMED_TO_SAME_CLASS_CONTEXT_KEY])) && $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {
118119
if (!$this->serializer instanceof NormalizerInterface) {
119120
throw new LogicException('Cannot normalize the output because the injected serializer is not a normalizer');
@@ -645,6 +646,7 @@ protected function getDataTransformer($data, string $to, array $context = []): ?
645646
* For a given resource, it returns an output representation if any
646647
* If not, the resource is returned.
647648
*/
649+
648650
protected function transformOutput($object, array $context = [], string $outputClass = null)
649651
{
650652
if (null === $outputClass) {

0 commit comments

Comments
 (0)