setLogger() public method

Set logger instance.
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface PSR-3 Logger
Exemplo n.º 1
0
 /**
  * Get Jabber client
  *
  * @access public
  * @return \Fabiang\Xmpp\Client
  */
 public function getClient()
 {
     $options = new Options($this->config->get('jabber_server'));
     $options->setUsername($this->config->get('jabber_username'));
     $options->setPassword($this->config->get('jabber_password'));
     $options->setTo($this->config->get('jabber_domain'));
     $options->setLogger($this->logger);
     return new Client($options);
 }
Exemplo n.º 2
0
 /**
  * Send message to the XMPP server
  *
  * @access public
  * @param  integer  $project_id
  * @param  string   $payload
  */
 public function sendMessage($project_id, $payload)
 {
     try {
         $params = $this->getParameters($project_id);
         $options = new Options($params['server']);
         $options->setUsername($params['username']);
         $options->setPassword($params['password']);
         $options->setTo($params['domain']);
         $options->setLogger($this->container['logger']);
         $client = new Client($options);
         $channel = new Presence();
         $channel->setTo($params['room'])->setNickName($params['nickname']);
         $client->send($channel);
         $message = new Message();
         $message->setMessage($payload)->setTo($params['room'])->setType(Message::TYPE_GROUPCHAT);
         $client->send($message);
         $client->disconnect();
     } catch (Exception $e) {
         $this->container['logger']->error('Jabber error: ' . $e->getMessage());
     }
 }
Exemplo n.º 3
0
 public function getClient($host, $username = null, $password = null)
 {
     $address = "tcp://{$host}:5222";
     $options = new Options($address);
     if ($this->logger) {
         $options->setLogger($this->logger);
     }
     if ($username && $password) {
         $this->log("Logging with {$username} | {$password}");
         $options->setUsername($username)->setPassword($password);
         $options->setImplementation(new AuthenticatedImplementation());
     } else {
         $options->setImplementation(new AnonymousImplementation());
         $options->setAuthenticationClasses([]);
     }
     $client = new Client($options);
     $client->connect();
     return $client;
 }