/** * Create a new Emitter instance * * @param integer $propogation The event propagation behvaiour (\Happen\Eventspace::NONE, \Happen\Eventspace::BUBBLE or \Happen\Eventspace::DESCEND). */ public function __construct($propogation = Eventspace::BUBBLE) { $this->event_queue = array(); $this->watcher = \EvIdle::createStopped(array($this, 'onIdle')); $this->propagation = $propogation; $this->eventspace = new Eventspace(); }
/** * Called when I\O isn't happening to process RPC queue. * * This should only be called by the event loop. * * @param \EvIdle $watcher * @param integer $revents * @return void */ public function _onIdle(\EvIdle $watcher, $revents) { // Get the first RPC in the queue. $rpc = array_shift($this->rpc_queue); if (!$rpc instanceof Rpc) { return $watcher->stop(); } // Make method call. $method_name = self::ACTION_METHOD_PREFIX . ucfirst(strtolower($rpc->type)); if (method_exists($this, $method_name)) { $rpc->response = call_user_func(array($this, $method_name), $rpc->name, $rpc->arguments); } // Add the data to the output queue to return response to parent process. $this->response_queue[] = serialize($rpc); // Make sure the output pipe watcher is runnning to dump queue contents. if (!$this->watchers[1]->is_active) { $this->watchers[1]->start(); } return true; }