Skip to content
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

createEntityFromMetadata not use entityExtractor result #9

Open
weierophinney opened this issue Dec 31, 2019 · 3 comments
Open

createEntityFromMetadata not use entityExtractor result #9

weierophinney opened this issue Dec 31, 2019 · 3 comments

Comments

@weierophinney
Copy link
Contributor

Using Apigility, I configured a service with Reflection Hydrator (in my case a custom hydrator which transforms the array properties keys into camel-case).

The problem is that every elaboration on the object made by the hydrator are unused: I notice in ResourceFactory.php there is:

55)    $data = $this->entityExtractor->extract($object);
       [...]
72)    $halEntity = new Entity($object, $id);

where $object is the original object.

If I pass $data to the Entity constructor, as I expected, everything works.
Did I misunderstand the meaning of this lines?


Originally posted by @DanielBertocci at zfcampus/zf-hal#143

@weierophinney
Copy link
Contributor Author

A HalEntity is not a $object which may also be an entity. The HalEntity is a wrapper around the entity.


Originally posted by @TomHAnderson at zfcampus/zf-hal#143 (comment)

@weierophinney
Copy link
Contributor Author

Thank you @TomHAnderson. Yes HalEntity is a wrapper, but I think it should wrap $data and not $object, otherwise almost all operations behind this call: $data = $this->entityExtractor->extract($object); are useless!


Originally posted by @DanielBertocci at zfcampus/zf-hal#143 (comment)

@weierophinney
Copy link
Contributor Author

The EntityExtractor has a cache ($serializedEntities) so next time the same entity will be extracted it will be resolved from that storage. This means that your statement that it is useless is not totally correct in this case.

This issue is actually a duplicate, I was also wondering about the exact same thing in this issue: zfcampus/zf-hal#64

This issue is from october 2014 so some variable names changed but the question is about the same issue. @weierophinney answered as follows:

The reason is so that when later events are triggered, developers have access to the original, raw entity in case they wish to do introspection or manipulation of it prior to rendering.

Hope this helps.


Originally posted by @Wilt at zfcampus/zf-hal#143 (comment)

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

No branches or pull requests

1 participant