public function registerListener(EventListener $eventListener) { $events = $eventListener->getEvents(); foreach ($events as $e) { if (!isset($this->listeners[$e])) { $this->listeners[$e] = array(); } $this->listeners[$e][] = $eventListener; } }
public function __construct($port, $timeout, $max_connection) { $this->_log =& new FileLog('logs/ftpproxy.log'); $this->_log->reset(); $this->_server_daemon =& new BasicServer($port, $timeout, $max_connection); parent::__construct($this->_server_daemon); $this->_server_daemon->addEventListener($this); }
public function __construct(IDataSource &$ds, ICaddy &$caddy = null) { parent::__construct($ds); $ds->addEventListener($this); $this->_storage =& $ds; $this->_caddy =& $caddy; $this->_caddy_id = null; $this->_date_creation = null; $this->_date_update = null; }
public function removeListener(EventListener $listener) { unset($this->listeners[$listener->getName()]); }
/** * Detach all handlers implemented by an event listener. * * @param EventListener $listener * An event listener. */ public function detachListener(EventListener $listener) { foreach ($listener->getEventHandlers() as $name => $method) { if (!is_string($name)) { $name = $method; if (strpos($method, '.') !== false) { $splits = explode('.', $method); $method = $splits[count($splits) - 1]; } } $this->detachHandler($name, array($listener, $method)); } }
public function __construct(ListenableLog &$log) { parent::__construct($log); }
<?php error_reporting(E_ALL); $base = new EventBase(); $listener = new EventListener($base, 'callback_accept', $base, EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, "127.0.0.1:8000"); $listener->setErrorCallback('callback_accept_error'); $base->dispatch(); function callback_accept($listener, $fd, $address, $base) { echo "accept running...\n"; $buffer = new EventBufferEvent($base, $fd, EventBufferEvent::OPT_CLOSE_ON_FREE); $buffer->setCallbacks('callback_read', 'callback_write', 'callback_event', $base); $buffer->setTimeouts(3, 3); $buffer->enable(Event::READ); $data = 'server.hello'; $length = strlen($data); $buffer->write($data); echo "write output buffer, data: server.hello({$length})\n"; } function callback_accept_error($listener, $base) { echo "accept error running...\n"; fprintf(STDOUT, "Got an error %d (%s) on the listener. Shutting down.\n", EventUtil::getLastSocketErrno(), EventUtil::getLastSocketError()); $base->exit(); } function callback_read($buffer, $base) { echo "read running...\n"; $data = ''; while ($read = $buffer->read(1024)) { $data .= $read;
public function __construct(AbstractClient &$dispatcher) { parent::__construct($dispatcher); $this->_log =& new FileLog('logs/basicclient.log'); $this->_log->reset(); }