/** * Publishes an event to all the listeners listening to the specified event for the specified resource * * @param w2p_Core_Event $event * @return Dispatcher */ public function publish(w2p_Core_Event $event) { $resourceName = $event->getResourceName(); $eventName = $event->getEventName(); //Loop through all the wildcard handlers if (isset($this->_listeners['*']['*'])) { foreach ($this->_listeners['*']['*'] as $listener) { $listener->publish($event); } } //Dispatch wildcard Resources //These are events that are published no matter what the resource if (isset($this->_listeners['*'])) { foreach ($this->_listeners['*'] as $event => $listeners) { if ($event == $eventName) { foreach ($listeners as $listener) { $listener->publish($event); } } } } //Dispatch wildcard Events //these are listeners that are dispatched for a certain resource, despite the event if (isset($this->_listeners[$resourceName]['*'])) { foreach ($this->_listeners[$resourceName]['*'] as $listener) { $listener->publish($event); } } //Dispatch to a certain resource event if (isset($this->_listeners[$resourceName][$eventName])) { foreach ($this->_listeners[$resourceName][$eventName] as $listener) { $listener->publish($event); } } return $this; }
public function publish(w2p_Core_Event $event) { $hook = substr($event->getEventName(), 0, -5); switch ($hook) { case 'preStore': case 'postStore': case 'preCreate': case 'postCreate': case 'preUpdate': case 'postCreate': case 'preUpdate': case 'postUpdate': case 'preLoad': case 'postLoad': case 'preDelete': case 'postDelete': $this->{'hook_' . $hook}(); break; default: //do nothing } //error_log("{$event->resourceName} published {$event->eventName} to call hook_$hook"); }