what i give is what you want
in yii the event system is something like this :
first you should new(or init) the event source objects and then new(init) some event listeners
,then register the listener[s] to event source object .
later if you trigger some event ,the method of event listener will be called !
in yii CBehavior can listen some event of its “owner” .(if you are not familiar to this characteristic just look at the CActiveRecord 's event ,eg : afterXX beforXX … . and often we extends the CActiveRecordBehavior to listen these events )
the key point is that you must init or new both the event source object and the event listener eagerly .then manually register the listener to event source object .(if you use yii 's behavior just attach it to “owner” ).
but in wp . the thing is different .
when you call some method , we firstly to find if we register some hooks to this method . the register table is not in memory ,it often obtain by table or files .(the pub/sub design pattern can be implemented in different styles .)
lets say your example again:
in your view file ,you render a menu here we can define a hook point ,before you render it just trigger a event : ‘beforeXXMenuRender’. and some modules may listen to this event .if you use the yii 's event system you have to have the eventSource and eventListeners existed and hook it before the event triggered ! this means you should do some wasteful things (event may trigger or not be triggered ,and the module numbers may be unknown firstly .but you always do the registering eagerly !) . now we can realize it like this :
$eventName = 'beforeRenderMyMenu';
$params = array();
// now the menus will be collected from different modules .
// after the event completed
$menus = $params['allMenus'];
// render it
here we should find the listeners which listen to the event by the eventName . the registry table may record the relations .
if you add some module latter and want to listen some event. just write to this "table".
you just consider how to realize such a global event system . the symfony evemtDispatcher may give you some idea .