开发者

What's a good way to throw and handle events in PHP?

I am just trying to get a general idea about the event prcessing mechanism in PHP5 in as neat way as possible. First of all I understand that a PHP application is not exactly a persistent type, so the events may not make a lot of sense, but from the OO perspective it might be a very elegant way to "communicate" between the objects.

So I am thinking that it would make sense to separate the events on the external events, such as $_POST & $_GET and the internal ones, i.e. function callbacks.

As far as the external ones, is it a good idea to process the $_GETs and $_POSTs directly, or is it better t开发者_Go百科o wrap them into an event of some sort?

Also, in order to process the internal events, do you have to pass the reference to the event handler/dispatcher to each class so they know how to throw them? I was thinking to use the PEAR EventDispatcher to do the work, but I am open to other suggestions.

Thank you!


In my point of view, HTTP events could or must be handle in a Controller layer type. Your domain/application/core/whatever name you call your domain rules MUST not depend of Sessions, Requests (post, get) and etc.

Model must be decoupled from any interface/controller dependencies i.e: buttons form names, interfaces process and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜