weierophinney/PhlyRestfully — pull request #21 by MichaelGooden (2013-03-20 13:58:47+00:00)
Title: Custom HAL Links

This is an almost complete solution for #5. (except for the custom link properties, see: below)

(@weierophinney you mentioned in #5 that you can already put links into your `HalResource`/`HalCollection`, but as far as I can see the `RestfulJsonRenderer` overwrites that property with its single generated `self` link).
`HalResource` and `HalCollection` now have a `links` property, which is an empty array by default. `RestfulJsonRenderer` will now merge this new `links` property with the generated `self` link. It merges over the generated links so you can add your own `self` link to your `HalResource` or `HalCollection` to override the default.

At present you still have to assemble the links array yourself, as the `HalLinks` plugin does not have native support for doing full link creation with the optional parameters like `templated`. This is however a limitation of `HalLinks` and not these changes, so if you want those features for yourself then you can update `HalLinks`.

A possible place to inject your custom links seems to be in your resource listener, or your custom resource if you have one. One limitation with this is if you are returning a `Zend\Paginator` object as your `HalCollection::collection`, the custom links will not be inserted into the sub resources. I am currently looking at using a custom `Hydrator` class to turn the db result into my `Entity` and then into a `HalResource`, so I can put my custom links in there.