Skip to content

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

Merged
merged 1 commit into from
Oct 16, 2014

Conversation

dantleech
Copy link
Member

Conflicts:
CHANGELOG.md

@@ -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());
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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)

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 ...
Copy link
Member

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.

dantleech added a commit that referenced this pull request Oct 16, 2014
Correctly set type and serialize correct value for References
@dantleech dantleech merged commit 56b9b91 into master Oct 16, 2014
@dantleech dantleech deleted the fix_reference_edit branch October 16, 2014 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants