-
Notifications
You must be signed in to change notification settings - Fork 19
Correctly set type and serialize correct value for References #101
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
Conversation
@@ -112,7 +117,7 @@ public function denormalize($data, $class, $format = null, array $context = arra | |||
|
|||
if (isset($datum['value'])) { | |||
if ($datum['value'] != $property->getValue()) { | |||
$property->setValue($datum['value']); | |||
$property->setValue($datum['value'], $property->getType()); |
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.
For the record the type of the property was being reset to STRING everytime unless the property type is specified.
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 guess that depends on the php type of the value, no? if its an array, on the type of the first array element.
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.
Well updating the type is not supported currently (I am not sure I remember why). But it is strange that updating a property value should change its type? I would have thought that if a property already has a type assigned then it would keep that type and cast any subsequent value to that type.
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.
changing the type is supported by setting a value of a different type: https://github.com/phpcr/phpcr-api-tests/blob/master/tests/10_Writing/SetPropertyDynamicRebindingTest.php
the idea is indeed that setting a value of a different type changes the type of the property. setValue has an optional $type argument for the type constant, to force a specific type.
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.
ok. updated, seems more sane now. the type (when editing an existing property) is the type declared by the user (if it is omitted or deleted then it is null and the value is auto detected)
f483035
to
1e4f178
Compare
Conflicts: CHANGELOG.md
1e4f178
to
c9a7ab3
Compare
if (isset($datum['value'])) { | ||
if ($datum['value'] != $property->getValue()) { | ||
$property->setValue($datum['value']); | ||
// setValue doesn't like being passed a null value as a type ... |
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.
you could translate that to PropertyType::UNDEFINED. but your approach is just as well. PR seems good to me, go ahead and merge.
Correctly set type and serialize correct value for References
Conflicts:
CHANGELOG.md