Zend AMF custom dispatcher

落花浮王杯 提交于 2020-01-17 09:33:09

问题


Is it possible to use a custom dispatcher when using Zend_AMF?

I know I can pass either a class name or an object to setClass() for Zend_AMF.

However, when I pass an object to setClass, it does not seem to store a copy of that object. Instead it worksout the class name and then instantiates a copy of the object itself.

This is a problem as I use the yadif dependency injection container. Objects should be instantiated with constructor dependencies and/or property dependencies.

Since the Zend_Amf dispatcher does all the instantiating, I am not able to inject constructor dependencies and other dependencies to my objects.

If anyone has a strategy as to how I can overcome this without touching any of the code in Zend_AMF, that would be great :)


回答1:


The solution is to basically build a wrapper around Zend_Amf. The way it is written means that I had to copy most of the code in the handle and _handle() methods. I then had to modify some called methods to point to an instance of Zend_Amf I have created.

Finally, the dispatching was changed so that my own dispatcher was called, and the results returned.

Obviously not the most elegant solution, but hopefully they will rework Zend_AMF to be a bit more extensible in the future and allow us to hook into it much easily.

At the moment, I can still easily drop in an updated version of Zend_AMF into my "vendors" folder without modifying any of the code.



来源:https://stackoverflow.com/questions/6701797/zend-amf-custom-dispatcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!