Adds an event listener to log data emitted by a stream.

@param \Evenement\EventEmitter $emitter
@param \Phergie\Irc\ConnectionInterface $connection Connection
corresponding to the stream
425222
protected function addLogging(EventEmitter $emitter, ConnectionInterface $connection)
    {
        $emitter->on('data', $this->getOutputLogCallback($connection, 'debug'));
        $emitter->on('error', $this->getOutputLogCallback($connection, 'notice'));
    }
1256589
public function afterQuery(Event $event, $connection)
    {
        $profiler = $this->profiler;
        $profiler->stopProfile();
        $profile = $profiler->getLastProfile();
        $sql = $profile->getSQLStatement();
        $params = $profile->getSqlVariables();
        $params = json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        $executeTime = $profile->getTotalElapsedSeconds();
        $profiler->reset();
        $this->di->getLogger()->info("[$sql] [$params] [$executeTime]");
    }
1096109
public function getEventQueue(ConnectionInterface $connection)
    {
        if (!isset($this->queues[$connection])) {
            $this->queues[$connection] = new EventQueue;
        }
        return $this->queues[$connection];
    }
98609
protected function emit(\Plop\RecordInterface $record)
    {
        if (!$this->stream) {
            $this->stream = $this->open();
        }
        parent::emit($record);
    }
683159
public function execute(ConnectionInterface $connection, array $argv)
    {

        // initialize input/output instances
        $input = new ArgvInput($argv);
        $output = new BufferedOutput();

        // initialize the execution context
        $executionContext = new ExecutionContext();
        $executionContext->injectInput($input);
        $executionContext->injectOutput($output);
        $executionContext->injectApplication($this->getApplication());

        // start the execution context
        $executionContext->start();
        $executionContext->join();

        // write the result back to the connection
        $executionContext->write($connection);
    }
177528
public function onConnect($connection)
    {
        $connection->timeout_timerid = Timer::add(10, function () use ($connection) {
            Worker::log("Register auth timeout (".$connection->getRemoteIp()."). See http://wiki.workerman.net/Error4 for detail");
            $connection->close();
        }, null, false);
    }
170465
public function log($connection, $queue, $payload)
	{
		$failed_at = new DateTime;

		$this->getTable()->insert(compact('connection', 'queue', 'payload', 'failed_at'));
	}
293821
protected function addPendingEvent($connection, $event, $payload)
    {
        $connectionId = $connection->getName();
        $transactionLevel = $this->transactionLevel;

        $eventData = [
            'event' => $event,
            'payload' => is_object($payload) ? clone $payload : $payload,
        ];
        $transactionLevelEvents = &$this->pendingEvents[$connectionId][$transactionLevel];
        $transactionLevelEvents[count($transactionLevelEvents) - 1][] = $eventData;
    }
998136
public function collectTransactionEvent($event, $connection)
    {
        $source = [];

        if ($this->findSource) {
            try {
                $source = $this->findSource();
            } catch (\Exception $e) {
            }
        }

        $this->queries[] = [
            'query' => $event,
            'type' => 'transaction',
            'bindings' => [],
            'time' => 0,
            'source' => $source,
            'explain' => [],
            'connection' => $connection->getDatabaseName(),
            'hints' => null,
        ];
    }
979072
public function onConnection(AuthClient $connection)
    {
        //bubble the events up
        $connection->on('login_success', function(AuthClient $client, DisconnectPacket $packet) {
            $this->emit('login_success', [$client->getUsername(), $client->getUUID(), $packet]);
        });

        $connection->on('status_request', function(StatusResponsePacket $packet) {
            $this->emit('status_request', [$packet]);
        });

        $connection->on('close', function() use (&$connection) {
            $amount = count($this->clients);
            for($i = 0; $i<$amount; $i++) {
                /** @var $checkclient AuthClient */
                $checkclient = $this->clients[$i];
                //if we found our connection
                if($checkclient === $connection) {
                    //remove from array and reset the keys
                    unset($this->clients[$i]);
                    $this->clients = array_values($this->clients);
                    echo "A client disconnected. Now there are total ". ($amount - 1) . " clients.\n";
                    $this->emit('disconnect', []);
                    return;
                }
            }
        });

        //if there is an error with the connection echo the error and end the connection
        $connection->on('error', function($error, Connection $connection) {
            echo "ERROR: $error\n";
            $connection->end();
        });

        //add the connection to the list of tracked connections
        $this->clients[] = $connection;

        //echo how many are now online
        $count = count($this->clients);
        echo "New client conected: {$connection->getRemoteAddress()}. Clients online: $count.\n";
    }
8033
public function subscribe(ConnectionInterface $connection, stdClass $payload)
    {
        $this->saveConnection($connection);

        $connection->send(json_encode([
            'event' => 'pusher_internal:subscription_succeeded',
            'channel' => $this->channelName,
        ]));
    }
143261
protected function identifyUser(ConnectionInterface $connection, WriteStream $writeStream)
    {
        $password = $connection->getPassword();
        if ($password) {
            $writeStream->ircPass($password);
        }

        $writeStream->ircUser(
            $connection->getUsername(),
            $connection->getHostname(),
            $connection->getServername(),
            $connection->getRealname()
        );

        $writeStream->ircNick($connection->getNickname());
    }
832192
public function queryBuilder(ConnectionInterface $connection, String $connectionId=null) : QueryBuilderProvider
	{
		return new QueryBuilder($connection, $connectionId);
	}
301910
protected function addSecureConnection(ConnectionInterface $connection)
    {
        $hostname = $connection->getServerHostname();
        $port = $connection->getServerPort();

        $this->getSecureConnector($connection)
            ->connect($hostname . ':' . $port)
            ->then(
                function(DuplexStreamInterface $stream) use ($connection) {
                    $this->initializeStream($stream, $connection);
                    $this->emit('connect.after.each', array($connection, $connection->getData('write')));
                },
                function($error) use($connection) {
                    $this->emitConnectionError($error, $connection);
                }
            );
    }
2886
public function emit(ResponseInterface $response, EmitterInterface $emitter = null)
    {
        if (!$emitter) {
            $emitter = new ResponseEmitter();
        }
        $emitter->emit($response);
    }
630661
function Message(connection) {
  // Inherit from event emitter
  var that = this;
  EventEmitter.call(this);

  // Save the connection
  this.connection = connection;

  // If there is a body already, don't buffer
  if (connection.body) {
    that.body = connection.body;
    async.setImmediate(function () {
      that.emit('loaded');
    });
    return;
  }

  // Buffer the content of the connecftion
  connection.pipe(concat(function handleBuffer (buff) {
    // Save the body and emit a `loaded` event
    // DEV: The delay is so `async.waterfall` still operates when we enter it
    that.body = buff.length ? buff : '';
    async.setImmediate(function () {
      that.emit('loaded');
    });
  }));
}
776147
public function emitter(string $emitter, string $streamEmitter = null): void
    {
        $server = $this->server ?? $this->getServer();
        $server->setEmitter($emitter);

        $streamEmitter && $this->get('response')->setEmitter($streamEmitter);
    }