/** * Tests setPrefix(). */ public function testSetPrefix() { $prefix = 'prefix-string'; $generator = $this->getMockGenerator(); $write = new WriteStream(); $write->setGenerator($generator); $write->setPrefix($prefix); Phake::verify($generator, Phake::times(1))->setPrefix($prefix); }
/** * Reads from the XMPP Socket and writes to the IRC channel */ private function attachSocketReadTimer() { /** * Read messages from the socket and write them to the channel * * @noinspection PhpParamsInspection */ $this->client->addPeriodicTimer(1, function () { if (!$this->connected) { return; } $text = $this->xmppStream->read(); if (!empty($text)) { $messageParts = explode(' ', $text); $nickName = str_replace(['<', '>'], '', $messageParts[0]); if ($nickName != $this->getContainer()->get('config')['xmpp']['nickname'] && $nickName != $this->getContainer()->get('config')['irc']['nickname']) { $this->getContainer()->get('logger')->debug('Found a message in the XMPP socket. Writing it to the IRC channel'); $this->write->ircPrivmsg($this->getContainer()->get('config')['irc']['channel'], htmlspecialchars_decode($text)); } } }); }
/** * There are certain incoming events that the client processes internally. * These functions are essential to the client-server relationship: for example, * updating the connection's stored nickname, responding to PING events, etc. * * Any user-level IRC functionality handled internally by the client * should be implemented here. * * @param array $message Parser output * @param \Phergie\Irc\Client\React\WriteStream $write Write stream * corresponding to the read stream on which the event occurred * @param \Phergie\Irc\ConnectionInterface $connection Connection on * which the event occurred */ protected function processInput(array $message, WriteStream $write, ConnectionInterface $connection) { switch ($message['command']) { // Update connection's internal nickname when changed case 'NICK': if ($connection->getNickname() === $message['nick']) { $connection->setNickname($message['params']['nickname']); } break; // Play client-server ping-pong // Play client-server ping-pong case 'PING': $write->ircPong($message['params']['server1']); break; } }
/** * @param string $msg */ public function send($msg) { $this->writeStream->ircPrivmsg($this->channel, $msg); }
/** * Identifies the user to a server. * * @param \Phergie\Irc\ConnectionInterface $connection Connection on which * to identify the user * @param \Phergie\Irc\Client\React\WriteStream $writeStream Stream to * receive commands identifying the user */ 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()); }
/** * Joins all the channels added to auto join list * @param WriteStream $writeStream WriteStream object * @return void */ public function trigger(WriteStream $writeStream) { foreach ($this->list as $channel => $key) { $writeStream->ircJoin($channel, $key); } }