/**
  * Constructor that called the parent \Exception constructor
  *
  * @param      string                $message  Error message
  * @param      int                   $code     Error level
  * @param      \Exception|null       $previous Previous \Exception or \Error
  */
 public function __construct(string $message, int $code = 0, $previous = null)
 {
     parent::__construct($message, $code, $previous);
     Ini::setIniFileName('conf.ini');
     $this->logger = new Logger(Ini::getParam('Exception', 'implementedLogger'));
     $this->logger->log($code, $message, parent::getTrace());
 }
Exemplo n.º 2
0
 /**
  * Index a document in ES (a chat message)
  *
  * @param      Client            $clientFrom  The client to send the message from
  * @param      ClientCollection  $clientsTo   The client(s) to send the message
  * @param      Room              $room        The room
  * @param      string            $message     The text message
  * @param      string            $type        The message type ('public' || 'private')
  * @param      string            $date        The server micro timestamp at the moment the message was sent
  */
 private function indexMessage(Client $clientFrom, ClientCollection $clientsTo, Room $room, string $message, string $type, string $date)
 {
     if ($clientFrom->getConnection()->getRemoteAddress() !== '127.0.0.1') {
         foreach ($clientsTo as $clientTo) {
             $es = EsClientBuilder::create()->build();
             $params = ['index' => $this->esIndex . '_write', 'type' => 'message', 'body' => ['message' => $message, 'type' => $type, 'date' => $date, 'room' => $room->id, 'userFrom' => ['id' => $clientFrom->isRegistered() ? $clientFrom->getUser()->id : -1, 'ip' => $clientFrom->getConnection()->getRemoteAddress(), 'location' => $clientFrom->getLocation(), 'pseudonym' => $room->getClientPseudonym($clientFrom)], 'userTo' => ['id' => $clientTo->isRegistered() ? $clientTo->getUser()->id : -1, 'ip' => $clientTo->getConnection()->getRemoteAddress(), 'location' => $clientTo->getLocation(), 'pseudonym' => $room->getClientPseudonym($clientTo)]]];
             try {
                 $es->index($params);
             } catch (\Exception $e) {
                 $this->logger->log(LogLevel::ERROR, sprintf('[chatService] Document not indexed in ES `%s` %s', $e, static::formatVariable($params)));
             }
         }
     }
 }
 /**
  * Service dispatcher to call the class which can treat the client request
  *
  * @param      array                                   $data    JSON decoded client data
  * @param      Client                                  $client  The client calling the request
  *
  * @return     \Generator|\Icicle\Awaitable\Awaitable
  */
 private function serviceSelector(array $data, Client $client)
 {
     $this->logger->log(LogLevel::DEBUG, 'Data: ' . static::formatVariable($data));
     foreach ($data['service'] as $service) {
         switch ($service) {
             case $this->services['clientService']->getServiceName():
                 (yield $this->services['clientService']->process($data, $client));
                 break;
             case 'chatService':
                 break;
             default:
                 (yield $this->services[$service]->process($data, $client, $this->rooms));
         }
     }
 }
 /**
  * Log the Exception / Error thrown
  *
  * @param      \Throwable  $t      The Exception / Error thrown
  */
 public function log(\Throwable $t)
 {
     $this->logger->log($t->getCode(), $t->getMessage(), $t->getTrace());
 }