addConnection() public method

Emits connect.before.each and connect.after.each events before and after connection attempts are established, respectively. Emits a connect.error event if a connection attempt fails.
public addConnection ( Phergie\Irc\ConnectionInterface $connection )
$connection Phergie\Irc\ConnectionInterface Metadata for connection to establish
Example #1
0
 /**
  * Watches for a DC and reconnects to IRC
  */
 private function attachDisconnectListener()
 {
     $this->client->on('connect.end', function (Connection $connection, LoggerInterface $logger) {
         /**
          * @var Connection $connection
          * @var Client     $client
          */
         $logger->debug('Connection to ' . $connection->getServerHostname() . ' lost, attempting to reconnect');
         $this->client->addConnection($connection);
     });
 }
 /**
  * Tests that the client emits a periodic event per connection.
  */
 public function testTickCallback()
 {
     $connection = $this->getMockConnectionForAddConnection();
     $logger = $this->getMockLogger();
     $loop = $this->getMockLoop();
     $writeStream = $this->getMockWriteStream();
     $timer = $this->getMockTimer();
     Phake::when($this->client)->getWriteStream($connection)->thenReturn($writeStream);
     Phake::when($loop)->addPeriodicTimer(0.2, $this->isType('callable'))->thenReturn($timer);
     $this->client->setLoop($loop);
     $this->client->setLogger($logger);
     $this->client->setResolver($this->getMockResolver());
     $this->client->addConnection($connection);
     Phake::verify($loop)->addPeriodicTimer(0.2, Phake::capture($callback));
     $callback();
     Phake::verify($this->client)->emit('irc.tick', Phake::capture($params));
     $this->assertInternalType('array', $params);
     $this->assertCount(3, $params);
     $this->assertSame($writeStream, $params[0]);
     $this->assertSame($connection, $params[1]);
     $this->assertSame($logger, $params[2]);
 }
Example #3
0
 /**
  * @param ConnectionInterface $connection
  * @return void
  */
 public function addConnection(ConnectionInterface $connection)
 {
     $this->client->addConnection($connection);
 }