Skip to content

Commit

Permalink
fix(jsonld): check if supportedTypes exists (api-platform#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored Nov 29, 2024
1 parent 7c9cca6 commit 4d7deea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/JsonLd/Serializer/ErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function supportsNormalization(mixed $data, ?string $format = null, array

public function getSupportedTypes(?string $format): array
{
return $this->inner->getSupportedTypes($format);
if (method_exists($this->inner, 'getSupportedTypes')) {
return $this->inner->getSupportedTypes($format);
}

return [];
}
}
10 changes: 8 additions & 2 deletions src/Metadata/Util/PropertyInfoToTypeInfoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException;
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\BuiltinType;
use Symfony\Component\TypeInfo\Type\NullableType;
use Symfony\Component\TypeInfo\Type\UnionType;
use Symfony\Component\TypeInfo\TypeIdentifier;

Expand Down Expand Up @@ -126,11 +127,16 @@ public static function createTypeFromLegacyValues(string $builtinType, bool $nul

public static function unwrapNullableType(Type $type): Type
{
if (!$type instanceof UnionType) {
// BC layer for "symfony/type-info" < 7.2
if (method_exists($type, 'asNonNullable')) {
return (!$type instanceof UnionType) ? $type : $type->asNonNullable();
}

if (!$type instanceof NullableType) {
return $type;
}

return $type->asNonNullable();
return $type->getWrappedType();
}

/**
Expand Down

0 comments on commit 4d7deea

Please sign in to comment.