public function processOutgoingEvents(ConnectionInterface $connection, WriteStream $write)
{
$client = $this->getClient();
$queue = $this->getEventQueueFactory()->getEventQueue($connection);
$client->emit('irc.sending.all', [$queue]);
while ($extracted = $queue->extract()) {
$extracted->setConnection($connection);
$params = [$extracted, $queue];
$subtype = $this->getEventSubtype($extracted);
$client->emit('irc.sending.each', $params);
$client->emit('irc.sending.' . $subtype, $params);
if ($extracted instanceof CtcpEvent) {
$method = 'ctcp' . $extracted->getCtcpCommand();
if ($extracted->getCommand() === 'NOTICE') {
$method .= 'Response';
}
} else {
$method = 'irc' . $extracted->getCommand();
}
call_user_func_array([$write, $method], $extracted->getParams());
}
}