Lynda assumes that there is a system service and several modules need to use the service. components can subscribe to this service or message and notify all modules through system broadcast. None? Php subscription publishing Mode Interface Definition and message transmission classDispatcher {monitor publicstatic $ listenersarray (); protectedfunction _ constru
Lynda assumes that there is a system service and several modules need to use the service. components can subscribe to this service or message and notify all modules through system broadcast. None? Php // subscription publishing Mode Interface Definition and message passing class Dispatcher {// monitoring public static $ listeners = array (); protected function _ constru
Lynda
Suppose there is a system service, and several modules need to use the service. The component can subscribe to this service or message and notify all modules through system broadcast. <无>
DoSomething () ;}} class Service {protected $ name = ''; public function _ construct ($ name) {$ this-> name = $ name ;} // trigger the public function doSomething () {echo sprintf ("% s has something happened. \ n ", $ this-> name); Dispatcher: publish ($ this) ;}} class Component {protected $ name = ''; public function _ construct ($ name) {$ this-> name = $ name;} public function doSomething () {echo sprintf ("% s did something. \ n ", $ this-> name) ;}$ serviceA = new Service (" ServiceA "); $ componentA = new Component (" componentA "); $ componentB = new Component ("componentB"); $ componentC = new Component ("componentC"); Dispatcher: subscribe ($ serviceA, $ componentA); Dispatcher :: subscribe ($ serviceA, $ componentB); Dispatcher: subscribe ($ serviceA, $ componentC); // trigger an Action $ serviceA-> doSomething (); // output // ServiceA something happened. // componentA did something. // componentB did something. // componentC did something.