Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Argument objects #19277

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

Merged
merged 14 commits into from
Jul 11, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,13 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
$params = array_merge($params, $data[$paramName]);
}
} elseif ($allowed && !$ignored && (isset($data[$key]) || array_key_exists($key, $data))) {
$params[] = $data[$key];
// don't run set for a parameter passed to the constructor
unset($data[$key]);
$parameterData = $data[$key];
if (null !== $constructogrParameter->getClass()) {
$parameterData = $this->serializer->denormalize($parameterData, $constructorParameter->getClass()->getName(), null, $context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing the unset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad copy/paste, should be kept

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add $format as a new optional paremeter for instantiateObject and pass it to the serializer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot this comment, it would be a BC break: Add argument with a default value No

Copy link
Contributor Author

@theofidry theofidry Jul 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dunglas I'm doing a denormalize but the normalizer is... SerializerAware, not NormalizerAware. This works because of the way the serializer is setup but it's violating the interfaces. What should we do about it? Calling deserialize() even though it will be more expensive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also calling deserialize() will fail if you are using a serializer without any encoder, which might be the case when you are dealing with arrays and php objects, i.e. are not taking any JSON/XML input. Not likely in a regular app, but can happen in libraries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe can you add a instanceof NormalizerInterface check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant' we make the normalizer NormalizerAware instead and deprecate it's SerializerAware?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better. But it should be done in another PR.

}

// Don't run set for a parameter passed to the constructor
$params[] = $parameterData;
} elseif ($constructorParameter->isDefaultValueAvailable()) {
$params[] = $constructorParameter->getDefaultValue();
} else {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.