weierophinney/PhlyRestfully — pull request #14 by weierophinney (2013-03-12 14:30:44+00:00)
Title: How to set resource hydrators

(If I knew how to mark this issue as a question, I would.)

I sat down today and started to use PhlyRestfully in one of my current projects. I struggled a bit in a few areas, but in the end I was able to have a decent understanding of most of the most fundamental aspects of this module. I have, however, come to an obstacle I'm not sure how to get around.

I would prefer to have my services return objects, which is what they were doing prior to using PhlyRestfully. This allows me to keep my resource listener methods quite clean and allows me to preserve the usage of objects, which provides some benefits for me from time to time over simple array pass-throughs. I don't want to have to write the code to turn each of my objects (back) into arrays, if I can help it.

So, if I return an object, though, the RestfulJsonRenderer looks for an appropriate hydrator, then the default hydrator if one cannot be found. If none are found, then the entire operation collapse and that specific resource is simply skipped.

So, I added to Module.php, in the getServiceConfig() method, a line that sets the renderer's default hydrator to a newly instantiated Zend\Stdlib\Hydrator\ClassMethods object. This is all I need at this point in time, but I also know that there must be a better way.

Any help on this would be much appreciated. Thanks in advance.