-
-
Notifications
You must be signed in to change notification settings - Fork 910
fix(state): do not expose FQCN in DeserializeProvider on PartialDenormalizationException #7158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(state): do not expose FQCN in DeserializeProvider on PartialDenormalizationException #7158
Conversation
@@ -36,6 +37,7 @@ public function __construct( | |||
private readonly ?ProviderInterface $decorated, | |||
private readonly SerializerInterface $serializer, | |||
private readonly SerializerContextBuilderInterface $serializerContextBuilder, | |||
private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It bothers me that we need to inject this but I guess there's no other solution unless we only use reflection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if we want to use a short name, we need this service.
I would leave only a reflection, for simplicity. However, I can't assess how well it meets the general concept of the API Platform.
|
||
if (class_exists($expectedType) || interface_exists($expectedType)) { | ||
try { | ||
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName(); | |
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()?->getShortName(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked \ApiPlatform\Metadata\Resource\ResourceMetadataCollection::getOperation
, it always returns Operation
.
if (class_exists($expectedType) || interface_exists($expectedType)) { | ||
try { | ||
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName(); | ||
} catch (\Throwable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (\Throwable) { | |
} catch (OperationNotFoundException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
if (null === $normalizedType) { | ||
$classReflection = new \ReflectionClass($expectedType); | ||
$normalizedType = $classReflection->getShortName(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is quite sufficient actually (I thought we could re-use the current operation
in the normalizers/denormalizers) but indeed in that case the type may be another one then the current operation's one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should fetch the operation exactly for class in $expectedType
.
I reverted the addition of the metadata factory reflection is enough imo. |
86c5485
to
498d309
Compare
Also relates to https://github.com/api-platform/core/pull/6761/files