Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

createEntityFromMetadata not use entityExtractor result #143

Open
DanielBertocci opened this issue Jun 15, 2016 · 4 comments
Open

createEntityFromMetadata not use entityExtractor result #143

DanielBertocci opened this issue Jun 15, 2016 · 4 comments

Comments

@DanielBertocci
Copy link

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?

@TomHAnderson
Copy link
Contributor

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

@DanielBertocci
Copy link
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!

@Wilt
Copy link
Contributor

Wilt commented Jun 29, 2016

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: #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.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-hal; a new issue has been opened at laminas-api-tools/api-tools-hal#9.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants