-
Notifications
You must be signed in to change notification settings - Fork 51
When using a closure in the "route_params" config section the metadata_map in zf-hal the config isn't re-rendered correctly when making changes #95
Comments
Additional info from composer.lock
|
This is why we do not recommend using closures in configuration, particularly with Apigility; the UI is serializing and writing to those files directly! To be honest, I'm surprised you can use a closure there at all, and am trying to determine how that works; I don't see anywhere where we call the closure to get the value anywhere in zf-hal or ZF2! Until I can figure that out, one possible way to make this work is to modify the value during configuration merging. |
Here is where it happens in ZF-Hal: https://github.com/zfcampus/zf-hal/blob/master/src/Plugin/Hal.php#L1329 I found it when looking through the tests: https://github.com/zfcampus/zf-hal/blob/master/test/Plugin/HalTest.php#L844 What's the recommended approach to generate links from a complex object if not using closures? Thanks Ben |
Digging into this a little more: In ZF-Hal metadata map route_parameters are used when creating the 'self' link. These route parameters can be closures. However where links are specified in the metadata map and a route name and params are specified, closures may not be used in the params. This is due to the behaviour of Hal::marshalSelfLinkFromMetadata (called when creating the self link) vs Hal::marshalMetadataLinks the former calls any closures passed as route_parameters where the later does not. When an entity with an embedded link (not self) hits the Hal::renderEntity method any parameters which are closures have not had their values swapped for the result of calling the closure. Would you accept a pull request to fix this behaviour? |
I would also like support for rendering closures for other links then To solve my rendering of closures in the metadata correctly I now I made a
Maybe this could be a (temporary) solution for @benwaine too... |
@Wilt Thanks - I'll take a look at this when I'm back in the office on Monday. Looks like what I need. |
@Wilt - fixed my problem. Look forward to using your real fix in the next point release! |
Good to hear it worked for you. Not so sure about this real fix you are mentioning. I think you misinterpreted me, no real fix there yet... |
I needed to add a route parameter to a nested collection. I'm using doctrine so the objects returned from my controllers are entities. Entities have a reference to their parents so can be used to find the correct url parameters.
Eg - To obtain the the url: /list/:list_id/items[/:item_id]
I used the following zf-hal config:
When I make any change to any endpoint and the content is re-rendered:
The following error is output:
PHP Version:
Modules:
Any one have an idea what could be going on?
The text was updated successfully, but these errors were encountered: